//
// sparse1.cpp
//
// Code generation for function 'sparse1'
//

// Include files
#include "sparse1.h"
#include "CXSparseAPI.h"
#include "bigProduct.h"
#include "detrendIBI_priors_data.h"
#include "detrendIBI_priors_internal_types.h"
#include "eml_int_forloop_overflow_check.h"
#include "indexShapeCheck.h"
#include "introsort.h"
#include "rt_nonfinite.h"
#include "speye.h"
#include "warning.h"
#include "coder_array.h"
#include "CXSparse/CXSparseSupport/cs.h"
#include "CXSparse/CXSparseSupport/makeCXSparseMatrix.h"
#include "mwmathutil.h"
#include "CXSparse/CXSparseSupport/solve_from_qr.h"
#include <cstddef>
#include <cstring>

// Variable Definitions
static emlrtRSInfo xc_emlrtRSI{
    1656,                  // lineNo
    "assertValidIndexArg", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo md_emlrtRSI{
    1683,            // lineNo
    "permuteVector", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo xd_emlrtRSI{
    395,                 // lineNo
    "sparse/ctranspose", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo yd_emlrtRSI{
    24,                    // lineNo
    "sparse/locTranspose", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\locTranspose.m" // pathName
};

static emlrtRSInfo ae_emlrtRSI{
    29,                    // lineNo
    "sparse/locTranspose", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\locTranspose.m" // pathName
};

static emlrtRSInfo be_emlrtRSI{
    33,                    // lineNo
    "sparse/locTranspose", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\locTranspose.m" // pathName
};

static emlrtRSInfo ce_emlrtRSI{
    17,                    // lineNo
    "sparse/locTranspose", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\locTranspose.m" // pathName
};

static emlrtRSInfo de_emlrtRSI{
    176,             // lineNo
    "sparse/sparse", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo ee_emlrtRSI{
    33,              // lineNo
    "sparse/mtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo fe_emlrtRSI{
    49,         // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo ge_emlrtRSI{
    50,         // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo he_emlrtRSI{
    62,         // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo ie_emlrtRSI{
    74,         // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo je_emlrtRSI{
    86,         // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo ke_emlrtRSI{
    98,         // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo le_emlrtRSI{
    118,        // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo me_emlrtRSI{
    120,        // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo ne_emlrtRSI{
    124,        // lineNo
    "ssmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo oe_emlrtRSI{
    279,                 // lineNo
    "countNnzInProduct", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo pe_emlrtRSI{
    290,                 // lineNo
    "countNnzInProduct", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo re_emlrtRSI{
    302,            // lineNo
    "sparse/times", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo se_emlrtRSI{
    194,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo te_emlrtRSI{
    198,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo ue_emlrtRSI{
    200,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo ve_emlrtRSI{
    18,      // lineNo
    "spfun", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\lib\\matlab\\sparfun\\spfun.m" // pathName
};

static emlrtRSInfo we_emlrtRSI{
    456,                // lineNo
    "sparse/spfunImpl", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo xe_emlrtRSI{
    459,                // lineNo
    "sparse/spfunImpl", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo ye_emlrtRSI{
    462,                // lineNo
    "sparse/spfunImpl", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo af_emlrtRSI{
    1482,                 // lineNo
    "sparse/spallocLike", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo bf_emlrtRSI{
    423,           // lineNo
    "scalarBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo cf_emlrtRSI{
    424,           // lineNo
    "scalarBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo df_emlrtRSI{
    49,              // lineNo
    "sparse/sparse", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo ef_emlrtRSI{
    50,              // lineNo
    "sparse/sparse", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo ff_emlrtRSI{
    65,              // lineNo
    "sparse/sparse", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo gf_emlrtRSI{
    66,              // lineNo
    "sparse/sparse", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo hf_emlrtRSI{
    292,           // lineNo
    "sparse/plus", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo if_emlrtRSI{
    125,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo jf_emlrtRSI{
    130,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo kf_emlrtRSI{
    133,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo lf_emlrtRSI{
    135,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo mf_emlrtRSI{
    139,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo nf_emlrtRSI{
    142,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo of_emlrtRSI{
    146,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo pf_emlrtRSI{
    149,            // lineNo
    "sparse/binOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo qf_emlrtRSI{
    495,                // lineNo
    "allocEqsizeBinop", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo rf_emlrtRSI{
    227,                         // lineNo
    "sparseSparseEqHeightBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo sf_emlrtRSI{
    327,                          // lineNo
    "sparseSparseRowExpandBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo tf_emlrtRSI{
    317,                          // lineNo
    "sparseSparseRowExpandBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo uf_emlrtRSI{
    312,                          // lineNo
    "sparseSparseRowExpandBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo vf_emlrtRSI{
    284,                          // lineNo
    "sparseSparseRowExpandBinOp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pathName
};

static emlrtRSInfo wf_emlrtRSI{
    1460,         // lineNo
    "sparse/inv", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo xf_emlrtRSI{
    1456,              // lineNo
    "sparse/mldivide", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo
    yf_emlrtRSI{
        131,                         // lineNo
        "CXSparseAPI/iteratedSolve", // fcnName
        "D:\\Program "
        "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
        "internal\\CXSparseAPI.m" // pathName
    };

static emlrtRSInfo
    ag_emlrtRSI{
        158,                         // lineNo
        "CXSparseAPI/iteratedSolve", // fcnName
        "D:\\Program "
        "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
        "internal\\CXSparseAPI.m" // pathName
    };

static emlrtRSInfo
    bg_emlrtRSI{
        160,                         // lineNo
        "CXSparseAPI/iteratedSolve", // fcnName
        "D:\\Program "
        "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
        "internal\\CXSparseAPI.m" // pathName
    };

static emlrtRSInfo ug_emlrtRSI{
    275,           // lineNo
    "sparse/full", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo wg_emlrtRSI{
    54,                     // lineNo
    "sparse/parenAssign2D", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo jh_emlrtRSI{
    329,       // lineNo
    "realloc", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo kh_emlrtRSI{
    337,       // lineNo
    "realloc", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo lh_emlrtRSI{
    342,       // lineNo
    "realloc", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo oh_emlrtRSI{
    300,                 // lineNo
    "copyNonzeroValues", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo ph_emlrtRSI{
    264,          // lineNo
    "incrColIdx", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo qh_emlrtRSI{
    271,          // lineNo
    "decrColIdx", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pathName
};

static emlrtRSInfo
    rh_emlrtRSI{
        376,                      // lineNo
        "CXSparseAPI/iteratedQR", // fcnName
        "D:\\Program "
        "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
        "internal\\CXSparseAPI.m" // pathName
    };

static emlrtRSInfo
    sh_emlrtRSI{
        375,                      // lineNo
        "CXSparseAPI/iteratedQR", // fcnName
        "D:\\Program "
        "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
        "internal\\CXSparseAPI.m" // pathName
    };

static emlrtRSInfo th_emlrtRSI{
    297,            // lineNo
    "sparse/minus", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pathName
};

static emlrtRSInfo uh_emlrtRSI{
    35,              // lineNo
    "sparse/mtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo vh_emlrtRSI{
    216,        // lineNo
    "sfmtimes", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo wh_emlrtRSI{
    232,               // lineNo
    "sfmtimes_vector", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo xh_emlrtRSI{
    241,               // lineNo
    "sfmtimes_vector", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo yh_emlrtRSI{
    252,               // lineNo
    "sfmtimes_vector", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtRSInfo ai_emlrtRSI{
    258,               // lineNo
    "sfmtimes_vector", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pathName
};

static emlrtMCInfo c_emlrtMCI{
    53,        // lineNo
    19,        // colNo
    "flt2str", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+internal\\flt2str.m" // pName
};

static emlrtRTEInfo t_emlrtRTEI{
    1662,                  // lineNo
    31,                    // colNo
    "assertValidIndexArg", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo u_emlrtRTEI{
    1660,                  // lineNo
    31,                    // colNo
    "assertValidIndexArg", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo v_emlrtRTEI{
    178,             // lineNo
    39,              // colNo
    "sparse/sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo w_emlrtRTEI{
    29,              // lineNo
    23,              // colNo
    "sparse/mtimes", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo x_emlrtRTEI{
    300,                 // lineNo
    9,                   // colNo
    "countNnzInProduct", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo y_emlrtRTEI{
    454,                // lineNo
    34,                 // colNo
    "sparse/spfunImpl", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo ab_emlrtRTEI{
    59,             // lineNo
    27,             // colNo
    "sparse/binOp", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pName
};

static emlrtRTEInfo bb_emlrtRTEI{
    489,                // lineNo
    9,                  // colNo
    "allocEqsizeBinop", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pName
};

static emlrtRTEInfo cb_emlrtRTEI{
    1459,         // lineNo
    35,           // colNo
    "sparse/inv", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo
    db_emlrtRTEI{
        137,                         // lineNo
        35,                          // colNo
        "CXSparseAPI/iteratedSolve", // fName
        "D:\\Program "
        "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+"
        "internal\\CXSparseAPI.m" // pName
    };

static emlrtRTEInfo hb_emlrtRTEI{
    11,                                   // lineNo
    27,                                   // colNo
    "sparse/sparse_validateNumericIndex", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\private\\validateNumericIndex.m" // pName
};

static emlrtRTEInfo ob_emlrtRTEI{
    237,            // lineNo
    13,             // colNo
    "sparse/numel", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo sc_emlrtRTEI{
    1653,     // lineNo
    27,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo tc_emlrtRTEI{
    395,      // lineNo
    13,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo uc_emlrtRTEI{
    32,             // lineNo
    1,              // colNo
    "locTranspose", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\locTranspose.m" // pName
};

static emlrtRTEInfo vc_emlrtRTEI{
    275,      // lineNo
    1,        // colNo
    "mtimes", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo wc_emlrtRTEI{
    276,      // lineNo
    1,        // colNo
    "mtimes", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo xc_emlrtRTEI{
    57,       // lineNo
    25,       // colNo
    "mtimes", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo yc_emlrtRTEI{
    59,       // lineNo
    1,        // colNo
    "mtimes", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo ad_emlrtRTEI{
    197,     // lineNo
    9,       // colNo
    "binOp", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\binOp.m" // pName
};

static emlrtRTEInfo bd_emlrtRTEI{
    302,      // lineNo
    13,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo cd_emlrtRTEI{
    453,      // lineNo
    12,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo gd_emlrtRTEI{
    1460,     // lineNo
    13,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo hd_emlrtRTEI{
    1482,     // lineNo
    13,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo id_emlrtRTEI{
    272,      // lineNo
    13,       // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo jd_emlrtRTEI{
    35,       // lineNo
    9,        // colNo
    "mtimes", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\mtimes.m" // pName
};

static emlrtRTEInfo td_emlrtRTEI{
    1682,     // lineNo
    5,        // colNo
    "sparse", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\sparse.m" // pName
};

static emlrtRTEInfo ud_emlrtRTEI{
    54,              // lineNo
    42,              // colNo
    "parenAssign2D", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pName
};

static emlrtRTEInfo vd_emlrtRTEI{
    325,             // lineNo
    1,               // colNo
    "parenAssign2D", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pName
};

static emlrtRTEInfo wd_emlrtRTEI{
    326,             // lineNo
    1,               // colNo
    "parenAssign2D", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pName
};

static emlrtRTEInfo xd_emlrtRTEI{
    333,             // lineNo
    1,               // colNo
    "parenAssign2D", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pName
};

static emlrtRTEInfo yd_emlrtRTEI{
    334,             // lineNo
    1,               // colNo
    "parenAssign2D", // fName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\shared\\coder\\coder\\+coder\\+internal\\@"
    "sparse\\parenAssign2D.m" // pName
};

static emlrtRSInfo ci_emlrtRSI{
    53,        // lineNo
    "flt2str", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\eml\\+coder\\+internal\\flt2str.m" // pathName
};

// Function Declarations
static void b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
                               const emlrtMsgIdentifier *msgId, char_T ret[14]);

static const mxArray *b_sprintf(const emlrtStack *sp, const mxArray *m1,
                                const mxArray *m2, emlrtMCInfo *location);

static void emlrt_marshallIn(const emlrtStack *sp,
                             const mxArray *a__output_of_sprintf_,
                             const char_T *identifier, char_T y[14]);

static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
                             const emlrtMsgIdentifier *parentId, char_T y[14]);

// Function Definitions
namespace coder {
void sparse::allocEqsizeBinop(const emlrtStack *sp, const sparse *a,
                              const sparse *b, int32_T sn, int32_T sm,
                              sparse *s)
{
  emlrtStack st;
  int32_T highOrderA;
  int32_T nza;
  int32_T nzb;
  int32_T partialResults_idx_1;
  st.prev = sp;
  st.tls = sp->tls;
  nza = a->colidx[a->colidx.size(0) - 1] - 1;
  nzb = b->colidx[b->colidx.size(0) - 1] - 1;
  if ((a->m != b->m) || (a->n != b->n)) {
    if (a->n == 1) {
      nza = (a->colidx[a->colidx.size(0) - 1] - 1) * b->n;
    } else if (a->m == 1) {
      nza = (a->colidx[a->colidx.size(0) - 1] - 1) * b->m;
    }
    if (b->n == 1) {
      nzb = (b->colidx[b->colidx.size(0) - 1] - 1) * a->n;
    } else if (a->m == 1) {
      nzb = b->colidx[b->colidx.size(0) - 1] - 1;
    }
  }
  if (nza > MAX_int32_T - nzb) {
    int32_T highOrderB;
    int32_T lowOrderB;
    int32_T overflow;
    int32_T partialResults_idx_0_tmp;
    int32_T tmp;
    highOrderA = sn >> 16;
    partialResults_idx_1 = sn & 65535;
    highOrderB = sm >> 16;
    lowOrderB = sm & 65535;
    partialResults_idx_0_tmp = partialResults_idx_1 * lowOrderB;
    tmp = partialResults_idx_1 * highOrderB;
    partialResults_idx_1 = tmp << 16;
    overflow = tmp >> 16;
    if (overflow <= 0) {
      tmp = highOrderA * lowOrderB;
      overflow = tmp >> 16;
      if (overflow <= 0) {
        overflow = highOrderA * highOrderB;
        if (overflow <= 0) {
          if (partialResults_idx_0_tmp > MAX_int32_T - partialResults_idx_1) {
            partialResults_idx_1 =
                (partialResults_idx_0_tmp + partialResults_idx_1) - MAX_int32_T;
            overflow = 1;
          } else {
            partialResults_idx_1 += partialResults_idx_0_tmp;
          }
          if (partialResults_idx_1 > MAX_int32_T - (tmp << 16)) {
            overflow++;
          }
        }
      }
    }
    if (overflow != 0) {
      emlrtErrorWithMessageIdR2018a(sp, &bb_emlrtRTEI,
                                    "Coder:toolbox:SparseFuncAlmostFull",
                                    "Coder:toolbox:SparseFuncAlmostFull", 0);
    }
  }
  partialResults_idx_1 = nza + nzb;
  highOrderA = sn * sm;
  partialResults_idx_1 =
      muIntScalarMin_sint32(partialResults_idx_1, highOrderA);
  if (partialResults_idx_1 < 1) {
    partialResults_idx_1 = 1;
  }
  st.site = &qf_emlrtRSI;
  s->m = sm;
  s->n = sn;
  s->maxnz = partialResults_idx_1;
  s->d.set_size(&fc_emlrtRTEI, &st, partialResults_idx_1);
  s->rowidx.set_size(&gc_emlrtRTEI, &st, partialResults_idx_1);
  if (sn + 1 < 0) {
    emlrtNonNegativeCheckR2012b(static_cast<real_T>(sn + 1), &b_emlrtDCI, &st);
  }
  s->colidx.set_size(&hc_emlrtRTEI, &st, sn + 1);
}

void sparse::b_fillIn()
{
  int32_T i;
  int32_T idx;
  idx = 1;
  i = colidx.size(0);
  for (int32_T c{0}; c <= i - 2; c++) {
    int32_T ridx;
    ridx = colidx[c];
    colidx[c] = idx;
    while (ridx < colidx[c + 1]) {
      real_T val;
      int32_T currRowIdx;
      currRowIdx = rowidx[ridx - 1];
      val = d[ridx - 1];
      ridx++;
      if (val != 0.0) {
        d[idx - 1] = val;
        rowidx[idx - 1] = currRowIdx;
        idx++;
      }
    }
  }
  colidx[colidx.size(0) - 1] = idx;
}

void sparse::b_sparseSparseEqHeightBinOp(const emlrtStack *sp, const sparse *a,
                                         const sparse *b, sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 0;
  s->colidx[0] = 1;
  b_n = s->n;
  st.site = &rf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    int32_T aidx;
    int32_T bidx;
    int32_T bidx_tmp;
    int32_T moreAToDo_tmp;
    boolean_T moreAToDo;
    boolean_T moreBToDo;
    aidx = a->colidx[c];
    bidx_tmp = b->colidx[c];
    bidx = bidx_tmp - 1;
    moreAToDo_tmp = a->colidx[c + 1];
    moreAToDo = (a->colidx[c] < moreAToDo_tmp);
    moreBToDo = (bidx_tmp < b->colidx[c + 1]);
    while (moreAToDo || moreBToDo) {
      while ((aidx < moreAToDo_tmp) &&
             ((!moreBToDo) || (a->rowidx[aidx - 1] < b->rowidx[bidx]))) {
        s->d[didx] = 1.0;
        s->rowidx[didx] = a->rowidx[aidx - 1];
        didx++;
        aidx++;
      }
      moreAToDo = (aidx < moreAToDo_tmp);
      while ((bidx + 1 < b->colidx[c + 1]) &&
             ((!moreAToDo) || (b->rowidx[bidx] < a->rowidx[aidx - 1]))) {
        if (0.0 - b->d[bidx] != 0.0) {
          s->d[didx] = 0.0 - b->d[bidx];
          s->rowidx[didx] = b->rowidx[bidx];
          didx++;
        }
        bidx++;
      }
      while ((aidx < moreAToDo_tmp) && (bidx + 1 < b->colidx[c + 1]) &&
             (a->rowidx[aidx - 1] == b->rowidx[bidx])) {
        if (1.0 - b->d[bidx] != 0.0) {
          s->d[didx] = 1.0 - b->d[bidx];
          s->rowidx[didx] = b->rowidx[bidx];
          didx++;
        }
        bidx++;
        aidx++;
      }
      moreAToDo = (aidx < moreAToDo_tmp);
      moreBToDo = (bidx + 1 < b->colidx[c + 1]);
    }
    s->colidx[c + 1] = didx + 1;
  }
}

void sparse::b_sparseSparseRowExpandBinOp(const emlrtStack *sp,
                                          const sparse *rowA, const sparse *b,
                                          sparse *s, boolean_T expandB)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T bc;
  int32_T bcInc;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 0;
  s->colidx[0] = 1;
  b_n = s->n;
  bc = 0;
  bcInc = !expandB;
  st.site = &vf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    int32_T av;
    int32_T i;
    av = (rowA->colidx[c] != rowA->colidx[c + 1]);
    i = b->colidx[bc + 1];
    if (b->colidx[bc] == i) {
      if (av != 0) {
        i = s->m;
        for (int32_T r{0}; r < i; r++) {
          av = didx + r;
          s->d[av] = 1.0;
          s->rowidx[av] = r + 1;
        }
        didx += i;
      }
      s->colidx[c + 1] = didx + 1;
      bc += bcInc;
    } else {
      int32_T firstNonZeroRow_tmp;
      int32_T lastNonZeroRow_tmp;
      int32_T offset;
      firstNonZeroRow_tmp = b->rowidx[b->colidx[bc] - 1];
      lastNonZeroRow_tmp = b->rowidx[i - 2];
      if (av != 0) {
        st.site = &uf_emlrtRSI;
        if (firstNonZeroRow_tmp - 1 > 2147483646) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{0}; r <= firstNonZeroRow_tmp - 2; r++) {
          i = didx + r;
          s->d[i] = 1.0;
          s->rowidx[i] = r + 1;
        }
        didx = (didx + firstNonZeroRow_tmp) - 1;
      }
      offset = -1;
      st.site = &tf_emlrtRSI;
      if ((firstNonZeroRow_tmp <= lastNonZeroRow_tmp) &&
          (lastNonZeroRow_tmp > 2147483646)) {
        b_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&b_st);
      }
      for (int32_T r{firstNonZeroRow_tmp}; r <= lastNonZeroRow_tmp; r++) {
        i = b->colidx[bc] + offset;
        if (b->rowidx[i] == r) {
          real_T val;
          val = static_cast<real_T>(av) - b->d[i];
          if (val != 0.0) {
            s->d[didx] = val;
            s->rowidx[didx] = r;
            didx++;
          }
          offset++;
        } else if (av != 0) {
          s->d[didx] = 1.0;
          s->rowidx[didx] = r;
          didx++;
        }
      }
      if (av != 0) {
        av = lastNonZeroRow_tmp + 1;
        firstNonZeroRow_tmp = s->m;
        st.site = &sf_emlrtRSI;
        if ((lastNonZeroRow_tmp + 1 <= s->m) && (s->m > 2147483646)) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{av}; r <= firstNonZeroRow_tmp; r++) {
          i = ((didx + r) - lastNonZeroRow_tmp) - 1;
          s->rowidx[i] = r;
          s->d[i] = 1.0;
        }
        didx = (didx + firstNonZeroRow_tmp) - lastNonZeroRow_tmp;
      }
      s->colidx[c + 1] = didx + 1;
      bc += bcInc;
    }
  }
}

void sparse::c_sparseSparseRowExpandBinOp(const emlrtStack *sp,
                                          const sparse *rowA, const sparse *b,
                                          sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 1;
  s->colidx[0] = 1;
  b_n = s->n;
  st.site = &vf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    real_T av;
    if (rowA->colidx[c] == rowA->colidx[c + 1]) {
      av = 0.0;
    } else {
      av = rowA->d[rowA->colidx[c] - 1];
    }
    if (b->colidx[0] == b->colidx[1]) {
      if (av != 0.0) {
        int32_T firstNonZeroRow_tmp;
        firstNonZeroRow_tmp = s->m;
        for (int32_T r{0}; r < firstNonZeroRow_tmp; r++) {
          if (av != 0.0) {
            s->d[didx - 1] = av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
    } else {
      int32_T firstNonZeroRow_tmp;
      int32_T lastNonZeroRow_tmp;
      int32_T offset;
      firstNonZeroRow_tmp = b->rowidx[b->colidx[0] - 1];
      lastNonZeroRow_tmp = b->rowidx[b->colidx[1] - 2];
      if (av != 0.0) {
        st.site = &uf_emlrtRSI;
        if (firstNonZeroRow_tmp - 1 > 2147483646) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{0}; r <= firstNonZeroRow_tmp - 2; r++) {
          if (av != 0.0) {
            s->d[didx - 1] = av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      offset = -1;
      st.site = &tf_emlrtRSI;
      if ((firstNonZeroRow_tmp <= lastNonZeroRow_tmp) &&
          (lastNonZeroRow_tmp > 2147483646)) {
        b_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&b_st);
      }
      for (int32_T r{firstNonZeroRow_tmp}; r <= lastNonZeroRow_tmp; r++) {
        if (b->rowidx[b->colidx[0] + offset] == r) {
          if (av + 1.0 != 0.0) {
            s->d[didx - 1] = av + 1.0;
            s->rowidx[didx - 1] = r;
            didx++;
          }
          offset++;
        } else if (av != 0.0) {
          s->d[didx - 1] = av;
          s->rowidx[didx - 1] = r;
          didx++;
        }
      }
      if (av != 0.0) {
        firstNonZeroRow_tmp = lastNonZeroRow_tmp + 1;
        offset = s->m;
        st.site = &sf_emlrtRSI;
        if ((lastNonZeroRow_tmp + 1 <= s->m) && (s->m > 2147483646)) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{firstNonZeroRow_tmp}; r <= offset; r++) {
          if (av != 0.0) {
            s->d[didx - 1] = av;
            s->rowidx[didx - 1] = r;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
    }
  }
}

int32_T sparse::copyNonzeroValues(const emlrtStack *sp, sparse *b_this,
                                  d_struct_T *rhsIter, int32_T outStart,
                                  const ::coder::array<real_T, 1U> &rhs)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b;
  int32_T outIdx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  outIdx = outStart;
  b = b_this->m;
  st.site = &oh_emlrtRSI;
  if (b_this->m > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T k{0}; k < b; k++) {
    real_T rhsv;
    rhsv = rhs[rhsIter->idx - 1];
    rhsIter->idx++;
    rhsIter->row++;
    if (rhsv != 0.0) {
      b_this->rowidx[outIdx - 1] = k + 1;
      b_this->d[outIdx - 1] = rhsv;
      outIdx++;
    }
  }
  return outIdx;
}

void sparse::d_sparseSparseRowExpandBinOp(const emlrtStack *sp,
                                          const sparse *rowA, const sparse *b,
                                          sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T bc;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 1;
  s->colidx[0] = 1;
  b_n = s->n;
  bc = 0;
  st.site = &vf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    real_T av;
    int32_T offset;
    if (rowA->colidx[c] == rowA->colidx[c + 1]) {
      av = 0.0;
    } else {
      av = rowA->d[rowA->colidx[c] - 1];
    }
    offset = b->colidx[bc + 1];
    if (b->colidx[bc] == offset) {
      if (av != 0.0) {
        offset = s->m;
        for (int32_T r{0}; r < offset; r++) {
          if (av != 0.0) {
            s->d[didx - 1] = av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
      bc++;
    } else {
      int32_T firstNonZeroRow_tmp;
      int32_T lastNonZeroRow_tmp;
      firstNonZeroRow_tmp = b->rowidx[b->colidx[bc] - 1];
      lastNonZeroRow_tmp = b->rowidx[offset - 2];
      if (av != 0.0) {
        st.site = &uf_emlrtRSI;
        if (firstNonZeroRow_tmp - 1 > 2147483646) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{0}; r <= firstNonZeroRow_tmp - 2; r++) {
          if (av != 0.0) {
            s->d[didx - 1] = av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      offset = -1;
      st.site = &tf_emlrtRSI;
      if ((firstNonZeroRow_tmp <= lastNonZeroRow_tmp) &&
          (lastNonZeroRow_tmp > 2147483646)) {
        b_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&b_st);
      }
      for (int32_T r{firstNonZeroRow_tmp}; r <= lastNonZeroRow_tmp; r++) {
        if (b->rowidx[b->colidx[bc] + offset] == r) {
          if (av + 1.0 != 0.0) {
            s->d[didx - 1] = av + 1.0;
            s->rowidx[didx - 1] = r;
            didx++;
          }
          offset++;
        } else if (av != 0.0) {
          s->d[didx - 1] = av;
          s->rowidx[didx - 1] = r;
          didx++;
        }
      }
      if (av != 0.0) {
        offset = lastNonZeroRow_tmp + 1;
        firstNonZeroRow_tmp = s->m;
        st.site = &sf_emlrtRSI;
        if ((lastNonZeroRow_tmp + 1 <= s->m) && (s->m > 2147483646)) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{offset}; r <= firstNonZeroRow_tmp; r++) {
          if (av != 0.0) {
            s->d[didx - 1] = av;
            s->rowidx[didx - 1] = r;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
      bc++;
    }
  }
}

void sparse::e_sparseSparseRowExpandBinOp(const emlrtStack *sp,
                                          const sparse *rowA, const sparse *b,
                                          sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 1;
  s->colidx[0] = 1;
  b_n = s->n;
  st.site = &vf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    real_T av;
    if (rowA->colidx[c] == rowA->colidx[c + 1]) {
      av = 0.0;
    } else {
      av = rowA->d[rowA->colidx[c] - 1];
    }
    if (b->colidx[0] == b->colidx[1]) {
      if (0.0 - av != 0.0) {
        int32_T firstNonZeroRow_tmp;
        firstNonZeroRow_tmp = s->m;
        for (int32_T r{0}; r < firstNonZeroRow_tmp; r++) {
          if (0.0 - av != 0.0) {
            s->d[didx - 1] = 0.0 - av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
    } else {
      int32_T firstNonZeroRow_tmp;
      int32_T lastNonZeroRow_tmp;
      int32_T offset;
      firstNonZeroRow_tmp = b->rowidx[b->colidx[0] - 1];
      lastNonZeroRow_tmp = b->rowidx[b->colidx[1] - 2];
      if (0.0 - av != 0.0) {
        st.site = &uf_emlrtRSI;
        if (firstNonZeroRow_tmp - 1 > 2147483646) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{0}; r <= firstNonZeroRow_tmp - 2; r++) {
          if (0.0 - av != 0.0) {
            s->d[didx - 1] = 0.0 - av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      offset = -1;
      st.site = &tf_emlrtRSI;
      if ((firstNonZeroRow_tmp <= lastNonZeroRow_tmp) &&
          (lastNonZeroRow_tmp > 2147483646)) {
        b_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&b_st);
      }
      for (int32_T r{firstNonZeroRow_tmp}; r <= lastNonZeroRow_tmp; r++) {
        if (b->rowidx[b->colidx[0] + offset] == r) {
          if (1.0 - av != 0.0) {
            s->d[didx - 1] = 1.0 - av;
            s->rowidx[didx - 1] = r;
            didx++;
          }
          offset++;
        } else if (0.0 - av != 0.0) {
          s->d[didx - 1] = 0.0 - av;
          s->rowidx[didx - 1] = r;
          didx++;
        }
      }
      if (0.0 - av != 0.0) {
        firstNonZeroRow_tmp = lastNonZeroRow_tmp + 1;
        offset = s->m;
        st.site = &sf_emlrtRSI;
        if ((lastNonZeroRow_tmp + 1 <= s->m) && (s->m > 2147483646)) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{firstNonZeroRow_tmp}; r <= offset; r++) {
          if (0.0 - av != 0.0) {
            s->d[didx - 1] = 0.0 - av;
            s->rowidx[didx - 1] = r;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
    }
  }
}

void sparse::f_sparseSparseRowExpandBinOp(const emlrtStack *sp,
                                          const sparse *rowA, const sparse *b,
                                          sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T bc;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 1;
  s->colidx[0] = 1;
  b_n = s->n;
  bc = 0;
  st.site = &vf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    real_T av;
    int32_T offset;
    if (rowA->colidx[c] == rowA->colidx[c + 1]) {
      av = 0.0;
    } else {
      av = rowA->d[rowA->colidx[c] - 1];
    }
    offset = b->colidx[bc + 1];
    if (b->colidx[bc] == offset) {
      if (0.0 - av != 0.0) {
        offset = s->m;
        for (int32_T r{0}; r < offset; r++) {
          if (0.0 - av != 0.0) {
            s->d[didx - 1] = 0.0 - av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
      bc++;
    } else {
      int32_T firstNonZeroRow_tmp;
      int32_T lastNonZeroRow_tmp;
      firstNonZeroRow_tmp = b->rowidx[b->colidx[bc] - 1];
      lastNonZeroRow_tmp = b->rowidx[offset - 2];
      if (0.0 - av != 0.0) {
        st.site = &uf_emlrtRSI;
        if (firstNonZeroRow_tmp - 1 > 2147483646) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{0}; r <= firstNonZeroRow_tmp - 2; r++) {
          if (0.0 - av != 0.0) {
            s->d[didx - 1] = 0.0 - av;
            s->rowidx[didx - 1] = r + 1;
            didx++;
          }
        }
      }
      offset = -1;
      st.site = &tf_emlrtRSI;
      if ((firstNonZeroRow_tmp <= lastNonZeroRow_tmp) &&
          (lastNonZeroRow_tmp > 2147483646)) {
        b_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&b_st);
      }
      for (int32_T r{firstNonZeroRow_tmp}; r <= lastNonZeroRow_tmp; r++) {
        if (b->rowidx[b->colidx[bc] + offset] == r) {
          if (1.0 - av != 0.0) {
            s->d[didx - 1] = 1.0 - av;
            s->rowidx[didx - 1] = r;
            didx++;
          }
          offset++;
        } else if (0.0 - av != 0.0) {
          s->d[didx - 1] = 0.0 - av;
          s->rowidx[didx - 1] = r;
          didx++;
        }
      }
      if (0.0 - av != 0.0) {
        offset = lastNonZeroRow_tmp + 1;
        firstNonZeroRow_tmp = s->m;
        st.site = &sf_emlrtRSI;
        if ((lastNonZeroRow_tmp + 1 <= s->m) && (s->m > 2147483646)) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{offset}; r <= firstNonZeroRow_tmp; r++) {
          if (0.0 - av != 0.0) {
            s->d[didx - 1] = 0.0 - av;
            s->rowidx[didx - 1] = r;
            didx++;
          }
        }
      }
      s->colidx[c + 1] = didx;
      bc++;
    }
  }
}

void sparse::sparseSparseEqHeightBinOp(const emlrtStack *sp, const sparse *a,
                                       const sparse *b, sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 0;
  s->colidx[0] = 1;
  b_n = s->n;
  st.site = &rf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    int32_T aidx;
    int32_T bidx;
    int32_T bidx_tmp;
    int32_T moreAToDo_tmp;
    boolean_T moreAToDo;
    boolean_T moreBToDo;
    aidx = a->colidx[c];
    bidx_tmp = b->colidx[c];
    bidx = bidx_tmp - 1;
    moreAToDo_tmp = a->colidx[c + 1];
    moreAToDo = (a->colidx[c] < moreAToDo_tmp);
    moreBToDo = (bidx_tmp < b->colidx[c + 1]);
    while (moreAToDo || moreBToDo) {
      while ((aidx < moreAToDo_tmp) &&
             ((!moreBToDo) || (a->rowidx[aidx - 1] < b->rowidx[bidx]))) {
        s->d[didx] = 1.0;
        s->rowidx[didx] = a->rowidx[aidx - 1];
        didx++;
        aidx++;
      }
      moreAToDo = (aidx < moreAToDo_tmp);
      while ((bidx + 1 < b->colidx[c + 1]) &&
             ((!moreAToDo) || (b->rowidx[bidx] < a->rowidx[aidx - 1]))) {
        if (b->d[bidx] != 0.0) {
          s->d[didx] = b->d[bidx];
          s->rowidx[didx] = b->rowidx[bidx];
          didx++;
        }
        bidx++;
      }
      while ((aidx < moreAToDo_tmp) && (bidx + 1 < b->colidx[c + 1]) &&
             (a->rowidx[aidx - 1] == b->rowidx[bidx])) {
        if (b->d[bidx] + 1.0 != 0.0) {
          s->d[didx] = b->d[bidx] + 1.0;
          s->rowidx[didx] = b->rowidx[bidx];
          didx++;
        }
        bidx++;
        aidx++;
      }
      moreAToDo = (aidx < moreAToDo_tmp);
      moreBToDo = (bidx + 1 < b->colidx[c + 1]);
    }
    s->colidx[c + 1] = didx + 1;
  }
}

void sparse::sparseSparseRowExpandBinOp(const emlrtStack *sp,
                                        const sparse *rowA, const sparse *b,
                                        sparse *s, boolean_T expandB)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b_n;
  int32_T bc;
  int32_T bcInc;
  int32_T didx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  didx = 0;
  s->colidx[0] = 1;
  b_n = s->n;
  bc = 0;
  bcInc = !expandB;
  st.site = &vf_emlrtRSI;
  if (s->n > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T c{0}; c < b_n; c++) {
    int32_T av;
    int32_T i;
    av = (rowA->colidx[c] != rowA->colidx[c + 1]);
    i = b->colidx[bc + 1];
    if (b->colidx[bc] == i) {
      if (av != 0) {
        i = s->m;
        for (int32_T r{0}; r < i; r++) {
          av = didx + r;
          s->d[av] = 1.0;
          s->rowidx[av] = r + 1;
        }
        didx += i;
      }
      s->colidx[c + 1] = didx + 1;
      bc += bcInc;
    } else {
      int32_T firstNonZeroRow_tmp;
      int32_T lastNonZeroRow_tmp;
      int32_T offset;
      firstNonZeroRow_tmp = b->rowidx[b->colidx[bc] - 1];
      lastNonZeroRow_tmp = b->rowidx[i - 2];
      if (av != 0) {
        st.site = &uf_emlrtRSI;
        if (firstNonZeroRow_tmp - 1 > 2147483646) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{0}; r <= firstNonZeroRow_tmp - 2; r++) {
          i = didx + r;
          s->d[i] = 1.0;
          s->rowidx[i] = r + 1;
        }
        didx = (didx + firstNonZeroRow_tmp) - 1;
      }
      offset = -1;
      st.site = &tf_emlrtRSI;
      if ((firstNonZeroRow_tmp <= lastNonZeroRow_tmp) &&
          (lastNonZeroRow_tmp > 2147483646)) {
        b_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&b_st);
      }
      for (int32_T r{firstNonZeroRow_tmp}; r <= lastNonZeroRow_tmp; r++) {
        i = b->colidx[bc] + offset;
        if (b->rowidx[i] == r) {
          real_T val;
          val = static_cast<real_T>(av) + b->d[i];
          if (val != 0.0) {
            s->d[didx] = val;
            s->rowidx[didx] = r;
            didx++;
          }
          offset++;
        } else if (av != 0) {
          s->d[didx] = 1.0;
          s->rowidx[didx] = r;
          didx++;
        }
      }
      if (av != 0) {
        av = lastNonZeroRow_tmp + 1;
        firstNonZeroRow_tmp = s->m;
        st.site = &sf_emlrtRSI;
        if ((lastNonZeroRow_tmp + 1 <= s->m) && (s->m > 2147483646)) {
          b_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&b_st);
        }
        for (int32_T r{av}; r <= firstNonZeroRow_tmp; r++) {
          i = ((didx + r) - lastNonZeroRow_tmp) - 1;
          s->rowidx[i] = r;
          s->d[i] = 1.0;
        }
        didx = (didx + firstNonZeroRow_tmp) - lastNonZeroRow_tmp;
      }
      s->colidx[c + 1] = didx + 1;
      bc += bcInc;
    }
  }
}

} // namespace coder
static void b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
                               const emlrtMsgIdentifier *msgId, char_T ret[14])
{
  static const int32_T dims[2]{1, 14};
  emlrtCheckBuiltInR2012b((emlrtCTX)sp, msgId, src, (const char_T *)"char",
                          false, 2U, (void *)&dims[0]);
  emlrtImportCharArrayR2015b((emlrtCTX)sp, src, &ret[0], 14);
  emlrtDestroyArray(&src);
}

static const mxArray *b_sprintf(const emlrtStack *sp, const mxArray *m1,
                                const mxArray *m2, emlrtMCInfo *location)
{
  const mxArray *pArrays[2];
  const mxArray *m;
  pArrays[0] = m1;
  pArrays[1] = m2;
  return emlrtCallMATLABR2012b((emlrtCTX)sp, 1, &m, 2, &pArrays[0],
                               (const char_T *)"sprintf", true, location);
}

static void emlrt_marshallIn(const emlrtStack *sp,
                             const mxArray *a__output_of_sprintf_,
                             const char_T *identifier, char_T y[14])
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = const_cast<const char_T *>(identifier);
  thisId.fParent = nullptr;
  thisId.bParentIsCell = false;
  emlrt_marshallIn(sp, emlrtAlias(a__output_of_sprintf_), &thisId, y);
  emlrtDestroyArray(&a__output_of_sprintf_);
}

static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
                             const emlrtMsgIdentifier *parentId, char_T y[14])
{
  b_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

namespace coder {
void sparse::assertValidIndexArg(const emlrtStack *sp,
                                 const ::coder::array<int32_T, 1U> &s,
                                 ::coder::array<int32_T, 1U> &sint)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T ns;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  ns = s.size(0);
  sint.set_size(&sc_emlrtRTEI, sp, s.size(0));
  st.site = &xc_emlrtRSI;
  if (s.size(0) > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T k{0}; k < ns; k++) {
    if (s[k] >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(sp, &u_emlrtRTEI,
                                    "MATLAB:sparsfcn:largeIndex",
                                    "MATLAB:sparsfcn:largeIndex", 0);
    }
    if (s[k] <= 0) {
      emlrtErrorWithMessageIdR2018a(sp, &t_emlrtRTEI,
                                    "MATLAB:sparsfcn:nonPosIndex",
                                    "MATLAB:sparsfcn:nonPosIndex", 0);
    }
    sint[k] = s[k];
  }
}

void sparse::b_minus(const emlrtStack *sp, const sparse *b, sparse *s) const
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack st;
  int32_T didx;
  boolean_T x[2];
  boolean_T exitg1;
  boolean_T moreAToDo;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &th_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  if (((m != 1) && (b->m != 1) && (m != b->m)) ||
      ((n != 1) && (b->n != 1) && (n != b->n))) {
    emlrtErrorWithMessageIdR2018a(&st, &ab_emlrtRTEI, "MATLAB:dimagree",
                                  "MATLAB:dimagree", 0);
  }
  b_st.site = &if_emlrtRSI;
  sparse::allocEqsizeBinop(&b_st, this, b, muIntScalarMax_sint32(n, b->n),
                           muIntScalarMax_sint32(m, b->m), s);
  x[0] = (m == b->m);
  x[1] = (n == b->n);
  moreAToDo = true;
  didx = 0;
  exitg1 = false;
  while ((!exitg1) && (didx < 2)) {
    if (!x[didx]) {
      moreAToDo = false;
      exitg1 = true;
    } else {
      didx++;
    }
  }
  if (moreAToDo) {
    b_st.site = &jf_emlrtRSI;
    sparse::b_sparseSparseEqHeightBinOp(&b_st, this, b, s);
  } else if (n == 1) {
    if (b->m == 1) {
      b_st.site = &kf_emlrtRSI;
      sparse::e_sparseSparseRowExpandBinOp(&b_st, b, this, s);
    } else {
      int32_T b_n;
      b_st.site = &lf_emlrtRSI;
      didx = 0;
      s->colidx[0] = 1;
      b_n = s->n;
      c_st.site = &rf_emlrtRSI;
      if (s->n > 2147483646) {
        d_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&d_st);
      }
      for (int32_T c{0}; c < b_n; c++) {
        int32_T aidx;
        int32_T bidx;
        int32_T bidx_tmp;
        boolean_T moreBToDo;
        aidx = colidx[0];
        bidx_tmp = b->colidx[c];
        bidx = bidx_tmp - 1;
        moreAToDo = (colidx[0] < colidx[1]);
        moreBToDo = (bidx_tmp < b->colidx[c + 1]);
        while (moreAToDo || moreBToDo) {
          while ((aidx < colidx[1]) &&
                 ((!moreBToDo) || (rowidx[aidx - 1] < b->rowidx[bidx]))) {
            s->d[didx] = 1.0;
            s->rowidx[didx] = rowidx[aidx - 1];
            didx++;
            aidx++;
          }
          moreAToDo = (aidx < colidx[1]);
          while ((bidx + 1 < b->colidx[c + 1]) &&
                 ((!moreAToDo) || (b->rowidx[bidx] < rowidx[aidx - 1]))) {
            if (0.0 - b->d[bidx] != 0.0) {
              s->d[didx] = 0.0 - b->d[bidx];
              s->rowidx[didx] = b->rowidx[bidx];
              didx++;
            }
            bidx++;
          }
          while ((aidx < colidx[1]) && (bidx + 1 < b->colidx[c + 1]) &&
                 (rowidx[aidx - 1] == b->rowidx[bidx])) {
            if (1.0 - b->d[bidx] != 0.0) {
              s->d[didx] = 1.0 - b->d[bidx];
              s->rowidx[didx] = b->rowidx[bidx];
              didx++;
            }
            bidx++;
            aidx++;
          }
          moreAToDo = (aidx < colidx[1]);
          moreBToDo = (bidx + 1 < b->colidx[c + 1]);
        }
        s->colidx[c + 1] = didx + 1;
      }
    }
  } else if (b->n == 1) {
    if (m == 1) {
      b_st.site = &mf_emlrtRSI;
      sparse::b_sparseSparseRowExpandBinOp(&b_st, this, b, s, true);
    } else {
      int32_T b_n;
      b_st.site = &nf_emlrtRSI;
      didx = 0;
      s->colidx[0] = 1;
      b_n = s->n;
      c_st.site = &rf_emlrtRSI;
      if (s->n > 2147483646) {
        d_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&d_st);
      }
      for (int32_T c{0}; c < b_n; c++) {
        int32_T aidx;
        int32_T bidx;
        int32_T bidx_tmp;
        boolean_T moreBToDo;
        aidx = b->colidx[0] - 1;
        bidx_tmp = colidx[c];
        bidx = bidx_tmp - 1;
        moreAToDo = (b->colidx[0] < b->colidx[1]);
        moreBToDo = (bidx_tmp < colidx[c + 1]);
        while (moreAToDo || moreBToDo) {
          while ((aidx + 1 < b->colidx[1]) &&
                 ((!moreBToDo) || (b->rowidx[aidx] < rowidx[bidx]))) {
            if (0.0 - b->d[aidx] != 0.0) {
              s->d[didx] = 0.0 - b->d[aidx];
              s->rowidx[didx] = b->rowidx[aidx];
              didx++;
            }
            aidx++;
          }
          moreAToDo = (aidx + 1 < b->colidx[1]);
          while ((bidx + 1 < colidx[c + 1]) &&
                 ((!moreAToDo) || (rowidx[bidx] < b->rowidx[aidx]))) {
            s->d[didx] = 1.0;
            s->rowidx[didx] = rowidx[bidx];
            didx++;
            bidx++;
          }
          while ((aidx + 1 < b->colidx[1]) && (bidx + 1 < colidx[c + 1]) &&
                 (b->rowidx[aidx] == rowidx[bidx])) {
            if (1.0 - b->d[aidx] != 0.0) {
              s->d[didx] = 1.0 - b->d[aidx];
              s->rowidx[didx] = rowidx[bidx];
              didx++;
            }
            bidx++;
            aidx++;
          }
          moreAToDo = (aidx + 1 < b->colidx[1]);
          moreBToDo = (bidx + 1 < colidx[c + 1]);
        }
        s->colidx[c + 1] = didx + 1;
      }
    }
  } else if (m == 1) {
    b_st.site = &of_emlrtRSI;
    sparse::b_sparseSparseRowExpandBinOp(&b_st, this, b, s, false);
  } else if (b->m == 1) {
    b_st.site = &pf_emlrtRSI;
    sparse::f_sparseSparseRowExpandBinOp(&b_st, b, this, s);
  }
}

void sparse::b_realloc(const emlrtStack *sp, sparse *b_this,
                       int32_T numAllocRequested, int32_T ub1, int32_T lb2,
                       int32_T ub2, int32_T offs)
{
  array<real_T, 1U> dt;
  array<int32_T, 1U> rowidxt;
  emlrtStack b_st;
  emlrtStack st;
  int32_T numAlloc;
  int32_T overflow;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  rowidxt.set_size(&vd_emlrtRTEI, sp, b_this->rowidx.size(0));
  numAlloc = b_this->rowidx.size(0);
  for (overflow = 0; overflow < numAlloc; overflow++) {
    rowidxt[overflow] = b_this->rowidx[overflow];
  }
  dt.set_size(&wd_emlrtRTEI, sp, b_this->d.size(0));
  numAlloc = b_this->d.size(0);
  for (overflow = 0; overflow < numAlloc; overflow++) {
    dt[overflow] = b_this->d[overflow];
  }
  internal::bigProduct(b_this->m, b_this->n, &numAlloc, &overflow);
  if (overflow == 0) {
    st.site = &jh_emlrtRSI;
    internal::bigProduct(b_this->m, b_this->n, &numAlloc, &overflow);
    if (overflow != 0) {
      emlrtErrorWithMessageIdR2018a(&st, &ob_emlrtRTEI,
                                    "Coder:toolbox:SparseNumelTooBig",
                                    "Coder:toolbox:SparseNumelTooBig", 0);
    }
    numAlloc = b_this->m * b_this->n;
    numAlloc = muIntScalarMin_sint32(numAllocRequested, numAlloc);
    if (numAlloc <= 1) {
      numAlloc = 1;
    }
  } else if (numAllocRequested <= 1) {
    numAlloc = 1;
  } else {
    numAlloc = numAllocRequested;
  }
  b_this->rowidx.set_size(&xd_emlrtRTEI, sp, numAlloc);
  for (overflow = 0; overflow < numAlloc; overflow++) {
    b_this->rowidx[overflow] = 0;
  }
  b_this->d.set_size(&yd_emlrtRTEI, sp, numAlloc);
  for (overflow = 0; overflow < numAlloc; overflow++) {
    b_this->d[overflow] = 0.0;
  }
  b_this->maxnz = numAlloc;
  st.site = &kh_emlrtRSI;
  if (ub1 > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (numAlloc = 0; numAlloc < ub1; numAlloc++) {
    b_this->rowidx[numAlloc] = rowidxt[numAlloc];
    b_this->d[numAlloc] = dt[numAlloc];
  }
  st.site = &lh_emlrtRSI;
  if ((lb2 <= ub2) && (ub2 > 2147483646)) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (numAlloc = lb2; numAlloc <= ub2; numAlloc++) {
    overflow = (numAlloc + offs) - 1;
    b_this->rowidx[overflow] = rowidxt[numAlloc - 1];
    b_this->d[overflow] = dt[numAlloc - 1];
  }
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

int32_T sparse::copyNonzeroValues(const emlrtStack *sp, sparse *b_this,
                                  d_struct_T *rhsIter, int32_T outStart,
                                  const ::coder::array<real_T, 2U> &rhs)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T b;
  int32_T outIdx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  outIdx = outStart;
  b = b_this->m;
  st.site = &oh_emlrtRSI;
  if (b_this->m > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T k{0}; k < b; k++) {
    real_T rhsv;
    rhsv = rhs[rhsIter->idx - 1];
    rhsIter->idx++;
    rhsIter->row++;
    if (rhsv != 0.0) {
      b_this->rowidx[outIdx - 1] = k + 1;
      b_this->d[outIdx - 1] = rhsv;
      outIdx++;
    }
  }
  return outIdx;
}

void sparse::ctranspose(const emlrtStack *sp, sparse *y) const
{
  array<int32_T, 1U> counts;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack st;
  int32_T b_tmp;
  int32_T nl;
  int32_T numalloc;
  int32_T outridx;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  st.site = &xd_emlrtRSI;
  nl = n;
  b_st.site = &ce_emlrtRSI;
  c_st.site = &rc_emlrtRSI;
  if (n < 0) {
    emlrtErrorWithMessageIdR2018a(&c_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (n >= MAX_int32_T) {
    emlrtErrorWithMessageIdR2018a(
        &c_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  c_st.site = &sc_emlrtRSI;
  if (m < 0) {
    emlrtErrorWithMessageIdR2018a(&c_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (m >= MAX_int32_T) {
    emlrtErrorWithMessageIdR2018a(
        &c_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  y->m = n;
  y->n = m;
  c_st.site = &de_emlrtRSI;
  if (colidx[colidx.size(0) - 1] - 1 < 0) {
    emlrtErrorWithMessageIdR2018a(&c_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (colidx[colidx.size(0) - 1] - 1 >= MAX_int32_T) {
    emlrtErrorWithMessageIdR2018a(
        &c_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  if (colidx[colidx.size(0) - 1] - 1 < 0) {
    emlrtErrorWithMessageIdR2018a(&b_st, &v_emlrtRTEI,
                                  "Coder:toolbox:SparseNzmaxTooSmall",
                                  "Coder:toolbox:SparseNzmaxTooSmall", 0);
  }
  numalloc = colidx[colidx.size(0) - 1] - 1;
  numalloc = muIntScalarMax_sint32(numalloc, 1);
  y->d.set_size(&tc_emlrtRTEI, &b_st, numalloc);
  for (outridx = 0; outridx < numalloc; outridx++) {
    y->d[outridx] = 0.0;
  }
  y->maxnz = numalloc;
  b_tmp = m + 1;
  y->colidx.set_size(&rc_emlrtRTEI, &b_st, b_tmp);
  y->colidx[0] = 1;
  y->rowidx.set_size(&tc_emlrtRTEI, &b_st, numalloc);
  for (outridx = 0; outridx < numalloc; outridx++) {
    y->rowidx[outridx] = 0;
  }
  numalloc = m;
  for (int32_T c{0}; c < numalloc; c++) {
    y->colidx[c + 1] = 1;
  }
  y->fillIn();
  if ((m != 0) && (n != 0)) {
    numalloc = y->colidx.size(0);
    for (outridx = 0; outridx < numalloc; outridx++) {
      y->colidx[outridx] = 0;
    }
    numalloc = colidx[colidx.size(0) - 1];
    b_st.site = &yd_emlrtRSI;
    if (colidx[colidx.size(0) - 1] - 1 > 2147483646) {
      c_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&c_st);
    }
    for (outridx = 0; outridx <= numalloc - 2; outridx++) {
      y->colidx[rowidx[outridx]] = y->colidx[rowidx[outridx]] + 1;
    }
    y->colidx[0] = 1;
    b_st.site = &ae_emlrtRSI;
    if (b_tmp > 2147483646) {
      c_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&c_st);
    }
    for (outridx = 2; outridx <= b_tmp; outridx++) {
      y->colidx[outridx - 1] = y->colidx[outridx - 1] + y->colidx[outridx - 2];
    }
    counts.set_size(&uc_emlrtRTEI, &st, m);
    numalloc = m;
    for (outridx = 0; outridx < numalloc; outridx++) {
      counts[outridx] = 0;
    }
    b_st.site = &be_emlrtRSI;
    for (int32_T c{0}; c < nl; c++) {
      for (numalloc = colidx[c] - 1; numalloc + 1 < colidx[c + 1]; numalloc++) {
        b_tmp = counts[rowidx[numalloc] - 1];
        outridx = (b_tmp + y->colidx[rowidx[numalloc] - 1]) - 1;
        y->d[outridx] = d[numalloc];
        y->rowidx[outridx] = c + 1;
        counts[rowidx[numalloc] - 1] = b_tmp + 1;
      }
    }
  }
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

void sparse::decrColIdx(const emlrtStack *sp, sparse *b_this, int32_T col,
                        int32_T offs)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T a;
  int32_T b_tmp;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  a = col + 1;
  b_tmp = b_this->n + 1;
  st.site = &qh_emlrtRSI;
  if ((col + 1 <= b_tmp) && (b_tmp > 2147483646)) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T k{a}; k <= b_tmp; k++) {
    b_this->colidx[k - 1] = b_this->colidx[k - 1] - offs;
  }
}

void sparse::fillIn()
{
  int32_T i;
  int32_T idx;
  idx = 1;
  i = colidx.size(0);
  for (int32_T c{0}; c <= i - 2; c++) {
    int32_T ridx;
    ridx = colidx[c];
    colidx[c] = idx;
    int32_T exitg1;
    int32_T i1;
    do {
      exitg1 = 0;
      i1 = colidx[c + 1];
      if (ridx < i1) {
        real_T val;
        int32_T currRowIdx;
        val = 0.0;
        currRowIdx = rowidx[ridx - 1];
        while ((ridx < i1) && (rowidx[ridx - 1] == currRowIdx)) {
          val += d[ridx - 1];
          ridx++;
        }
        if (val != 0.0) {
          d[idx - 1] = val;
          rowidx[idx - 1] = currRowIdx;
          idx++;
        }
      } else {
        exitg1 = 1;
      }
    } while (exitg1 == 0);
  }
  colidx[colidx.size(0) - 1] = idx;
}

void b_sparse::full(const emlrtStack *sp, ::coder::array<real_T, 2U> &y) const
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T a;
  int32_T cend;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  y.set_size(&id_emlrtRTEI, sp, m, 1);
  cend = m;
  for (a = 0; a < cend; a++) {
    y[a] = 0.0;
  }
  cend = colidx[1] - 1;
  a = colidx[0];
  st.site = &ug_emlrtRSI;
  if ((colidx[0] <= colidx[1] - 1) && (colidx[1] - 1 > 2147483646)) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T idx{a}; idx <= cend; idx++) {
    y[rowidx[idx - 1] - 1] = d[idx - 1];
  }
}

void sparse::incrColIdx(const emlrtStack *sp, sparse *b_this, int32_T col,
                        int32_T offs)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T a;
  int32_T b_tmp;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  a = col + 1;
  b_tmp = b_this->n + 1;
  st.site = &ph_emlrtRSI;
  if ((col + 1 <= b_tmp) && (b_tmp > 2147483646)) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (int32_T k{a}; k <= b_tmp; k++) {
    b_this->colidx[k - 1] = b_this->colidx[k - 1] + offs;
  }
}

void sparse::inv(const emlrtStack *sp, sparse *y) const
{
  static const int32_T iv[2]{1, 6};
  static const char_T rfmt[6]{'%', '1', '4', '.', '6', 'e'};
  b_sparse r;
  sparse b;
  sparse in;
  array<real_T, 2U> r1;
  array<real_T, 1U> b_outBuff;
  array<real_T, 1U> outBuff;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  emlrtStack f_st;
  emlrtStack st;
  const mxArray *b_m;
  const mxArray *b_y;
  const mxArray *c_y;
  int32_T iv1[2];
  int32_T b_loop_ub;
  int32_T loop_ub;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  e_st.prev = &d_st;
  e_st.tls = d_st.tls;
  f_st.prev = &e_st;
  f_st.tls = e_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  if (m != n) {
    emlrtErrorWithMessageIdR2018a(sp, &cb_emlrtRTEI, "MATLAB:square",
                                  "MATLAB:square", 0);
  }
  st.site = &wf_emlrtRSI;
  b_st.site = &wf_emlrtRSI;
  speye(&b_st, static_cast<real_T>(m), &b);
  b_st.site = &xf_emlrtRSI;
  if ((m == 0) || (n == 0) || (b.m == 0) || (b.n == 0)) {
    int32_T rank;
    c_st.site = &yf_emlrtRSI;
    d_st.site = &af_emlrtRSI;
    e_st.site = &rc_emlrtRSI;
    if (n < 0) {
      emlrtErrorWithMessageIdR2018a(&e_st, &r_emlrtRTEI,
                                    "Coder:toolbox:SparseNegativeSize",
                                    "Coder:toolbox:SparseNegativeSize", 0);
    }
    if (n >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &e_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    e_st.site = &sc_emlrtRSI;
    if (b.n < 0) {
      emlrtErrorWithMessageIdR2018a(&e_st, &r_emlrtRTEI,
                                    "Coder:toolbox:SparseNegativeSize",
                                    "Coder:toolbox:SparseNegativeSize", 0);
    }
    if (b.n >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &e_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    y->m = n;
    y->n = b.n;
    y->d.set_size(&gd_emlrtRTEI, &d_st, 1);
    y->d[0] = 0.0;
    y->maxnz = 1;
    y->colidx.set_size(&rc_emlrtRTEI, &d_st, b.n + 1);
    y->colidx[0] = 1;
    y->rowidx.set_size(&gd_emlrtRTEI, &d_st, 1);
    y->rowidx[0] = 0;
    rank = b.n;
    e_st.site = &uc_emlrtRSI;
    for (int32_T b_n{0}; b_n < rank; b_n++) {
      y->colidx[b_n + 1] = 1;
    }
    e_st.site = &wc_emlrtRSI;
    y->fillIn();
  } else {
    if (m != b.m) {
      emlrtErrorWithMessageIdR2018a(&b_st, &db_emlrtRTEI, "MATLAB:dimagree",
                                    "MATLAB:dimagree", 0);
    }
    if (b.m == n) {
      c_st.site = &ag_emlrtRSI;
      internal::CXSparseAPI::iteratedLU(&c_st, this, &b, y);
    } else {
      cs_di *cxA;
      cs_din *N;
      cs_dis *S;
      real_T tol;
      int32_T A;
      int32_T b_n;
      int32_T rank;
      c_st.site = &bg_emlrtRSI;
      b_n = n;
      d_st.site = &lg_emlrtRSI;
      if (m < n) {
        e_st.site = &jg_emlrtRSI;
        f_st.site = &jg_emlrtRSI;
        ctranspose(&f_st, &in);
        cxA = makeCXSparseMatrix(in.colidx[in.colidx.size(0) - 1] - 1, in.n,
                                 in.m, &(in.colidx.data())[0],
                                 &(in.rowidx.data())[0], &(in.d.data())[0]);
      } else {
        e_st.site = &kg_emlrtRSI;
        cxA = makeCXSparseMatrix(
            colidx[colidx.size(0) - 1] - 1, n, m,
            &(((::coder::array<int32_T, 1U> *)&colidx)->data())[0],
            &(((::coder::array<int32_T, 1U> *)&rowidx)->data())[0],
            &(((::coder::array<real_T, 1U> *)&d)->data())[0]);
      }
      S = cs_di_sqr(2, cxA, 1);
      N = cs_di_qr(cxA, S);
      cs_di_spfree(cxA);
      rank = qr_rank_di(N, &tol);
      if (m > n) {
        A = n;
      } else {
        A = m;
      }
      if (rank < A) {
        char_T str[14];
        d_st.site = &rh_emlrtRSI;
        b_y = nullptr;
        b_m = emlrtCreateCharArray(2, &iv[0]);
        emlrtInitCharArrayR2013a(&d_st, 6, b_m, &rfmt[0]);
        emlrtAssign(&b_y, b_m);
        c_y = nullptr;
        b_m = emlrtCreateDoubleScalar(tol);
        emlrtAssign(&c_y, b_m);
        e_st.site = &ci_emlrtRSI;
        emlrt_marshallIn(&e_st, b_sprintf(&e_st, b_y, c_y, &c_emlrtMCI),
                         "<output of sprintf>", str);
        d_st.site = &sh_emlrtRSI;
        internal::warning(&d_st, rank, str);
      }
      d_st.site = &mg_emlrtRSI;
      sparse::spallocLike(&d_st, n, static_cast<real_T>(b.n), y);
      A = b.m;
      if (b.m < n) {
        outBuff.set_size(&ed_emlrtRTEI, &c_st, n);
      } else {
        outBuff.set_size(&dd_emlrtRTEI, &c_st, b.m);
      }
      rank = b.n;
      if (rank - 1 >= 0) {
        if (A < 1) {
          loop_ub = 0;
        } else {
          loop_ub = A;
        }
        if (b_n < 1) {
          b_loop_ub = 0;
        } else {
          b_loop_ub = b_n;
        }
        iv1[0] = 1;
        iv1[1] = b_loop_ub;
      }
      for (int32_T i{0}; i < rank; i++) {
        d_st.site = &ng_emlrtRSI;
        b.parenReference(&d_st, static_cast<real_T>(i) + 1.0, &r);
        d_st.site = &ng_emlrtRSI;
        r.full(&d_st, r1);
        for (A = 0; A < loop_ub; A++) {
          outBuff[A] = r1[A];
        }
        solve_from_qr_di(N, S, (double *)&(outBuff.data())[0], b.m, b_n);
        d_st.site = &og_emlrtRSI;
        internal::indexShapeCheck(&d_st, outBuff.size(0), iv1);
        b_outBuff.set_size(&fd_emlrtRTEI, &c_st, b_loop_ub);
        for (A = 0; A < b_loop_ub; A++) {
          b_outBuff[A] = outBuff[A];
        }
        d_st.site = &og_emlrtRSI;
        y->parenAssign(&d_st, b_outBuff, static_cast<real_T>(i) + 1.0);
      }
      cs_di_sfree(S);
      cs_di_nfree(N);
    }
  }
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

void sparse::mtimes(const emlrtStack *sp, const sparse *b, sparse *c) const
{
  array<real_T, 1U> wd;
  array<int32_T, 1U> flag;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack st;
  int32_T a_tmp;
  int32_T b_b;
  int32_T bcidx;
  int32_T cmax;
  int32_T cnnz;
  int32_T cstart;
  int32_T i;
  int32_T j;
  int32_T paend_tmp;
  int32_T pb;
  int32_T pcstart;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  if (n != b->m) {
    emlrtErrorWithMessageIdR2018a(sp, &w_emlrtRTEI, "MATLAB:innerdim",
                                  "MATLAB:innerdim", 0);
  }
  st.site = &ee_emlrtRSI;
  b_st.site = &fe_emlrtRSI;
  c->colidx.set_size(&vc_emlrtRTEI, &b_st, b->colidx.size(0));
  bcidx = b->colidx.size(0);
  for (i = 0; i < bcidx; i++) {
    c->colidx[i] = 0;
  }
  flag.set_size(&wc_emlrtRTEI, &b_st, m);
  bcidx = m;
  for (i = 0; i < bcidx; i++) {
    flag[i] = 0;
  }
  cnnz = 0;
  c_st.site = &oe_emlrtRSI;
  if (b->n > 2147483646) {
    d_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&d_st);
  }
  j = 0;
  int32_T exitg1;
  do {
    exitg1 = 0;
    if (j <= b->n - 1) {
      bcidx = b->colidx[j] - 1;
      cstart = cnnz;
      cmax = cnnz + m;
      c->colidx[j] = cnnz + 1;
      while ((bcidx + 1 < b->colidx[j + 1]) && (cnnz <= cmax)) {
        paend_tmp = colidx[b->rowidx[bcidx]] - 1;
        a_tmp = colidx[b->rowidx[bcidx] - 1];
        c_st.site = &pe_emlrtRSI;
        if ((a_tmp <= paend_tmp) && (paend_tmp > 2147483646)) {
          d_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&d_st);
        }
        for (pcstart = a_tmp; pcstart <= paend_tmp; pcstart++) {
          i = rowidx[pcstart - 1] - 1;
          if (flag[i] != j + 1) {
            flag[i] = j + 1;
            cnnz++;
          }
        }
        bcidx++;
      }
      if (cnnz < cstart) {
        emlrtErrorWithMessageIdR2018a(&b_st, &x_emlrtRTEI, "MATLAB:nomem",
                                      "MATLAB:nomem", 0);
      } else {
        j++;
      }
    } else {
      c->colidx[b->n] = cnnz + 1;
      exitg1 = 1;
    }
  } while (exitg1 == 0);
  b_st.site = &ge_emlrtRSI;
  c->m = m;
  c->n = b->n;
  if (cnnz < 1) {
    cnnz = 1;
  }
  c->maxnz = cnnz;
  c->d.set_size(&fc_emlrtRTEI, &b_st, cnnz);
  c->rowidx.set_size(&gc_emlrtRTEI, &b_st, cnnz);
  if (b->n + 1 < 0) {
    emlrtNonNegativeCheckR2012b(static_cast<real_T>(b->n + 1), &b_emlrtDCI,
                                &b_st);
  }
  wd.set_size(&xc_emlrtRTEI, &st, m);
  flag.set_size(&yc_emlrtRTEI, &st, m);
  bcidx = m;
  for (i = 0; i < bcidx; i++) {
    flag[i] = 0;
  }
  pb = 0;
  cnnz = -1;
  b_b = b->n;
  b_st.site = &he_emlrtRSI;
  for (j = 0; j < b_b; j++) {
    boolean_T needSort;
    needSort = false;
    pcstart = cnnz + 2;
    bcidx = (b->colidx[j + 1] - pb) - 1;
    if (bcidx != 0) {
      if (bcidx == 1) {
        paend_tmp = colidx[b->rowidx[pb]] - 1;
        a_tmp = colidx[b->rowidx[pb] - 1];
        b_st.site = &ie_emlrtRSI;
        if ((a_tmp <= paend_tmp) && (paend_tmp > 2147483646)) {
          c_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&c_st);
        }
        for (int32_T pa{a_tmp}; pa <= paend_tmp; pa++) {
          i = rowidx[pa - 1];
          c->rowidx[((cnnz + pa) - a_tmp) + 1] = i;
          wd[i - 1] = d[pa - 1] * b->d[pb];
        }
        cnnz = (cnnz + colidx[b->rowidx[pb]]) - colidx[b->rowidx[pb] - 1];
        pb++;
      } else {
        bcidx = colidx[b->rowidx[pb]];
        paend_tmp = bcidx - 1;
        a_tmp = colidx[b->rowidx[pb] - 1];
        b_st.site = &je_emlrtRSI;
        if ((a_tmp <= bcidx - 1) && (bcidx - 1 > 2147483646)) {
          c_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&c_st);
        }
        for (int32_T pa{a_tmp}; pa <= paend_tmp; pa++) {
          cstart = rowidx[pa - 1];
          cmax = (cnnz + pa) - a_tmp;
          flag[cstart - 1] = cmax + 2;
          c->rowidx[cmax + 1] = cstart;
          wd[cstart - 1] = d[pa - 1] * b->d[pb];
        }
        cnnz = (cnnz + bcidx) - a_tmp;
        for (pb++; pb + 1 < b->colidx[j + 1]; pb++) {
          real_T bd;
          bd = b->d[pb];
          paend_tmp = colidx[b->rowidx[pb]] - 1;
          a_tmp = colidx[b->rowidx[pb] - 1];
          b_st.site = &ke_emlrtRSI;
          if ((a_tmp <= paend_tmp) && (paend_tmp > 2147483646)) {
            c_st.site = &y_emlrtRSI;
            check_forloop_overflow_error(&c_st);
          }
          for (int32_T pa{a_tmp}; pa <= paend_tmp; pa++) {
            i = rowidx[pa - 1];
            if (flag[i - 1] < pcstart) {
              cnnz++;
              flag[i - 1] = cnnz + 1;
              c->rowidx[cnnz] = i;
              wd[i - 1] = d[pa - 1] * bd;
              needSort = true;
            } else {
              wd[i - 1] = wd[i - 1] + d[pa - 1] * bd;
            }
          }
        }
      }
    }
    bcidx = c->colidx[j + 1] - 1;
    cstart = c->colidx[j];
    if (needSort) {
      b_st.site = &le_emlrtRSI;
      internal::introsort(&b_st, c->rowidx, c->colidx[j], c->colidx[j + 1] - 1);
    }
    b_st.site = &me_emlrtRSI;
    if ((cstart <= c->colidx[j + 1] - 1) &&
        (c->colidx[j + 1] - 1 > 2147483646)) {
      c_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&c_st);
    }
    for (cmax = cstart; cmax <= bcidx; cmax++) {
      c->d[cmax - 1] = wd[c->rowidx[cmax - 1] - 1];
    }
  }
  b_st.site = &ne_emlrtRSI;
  c->b_fillIn();
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

void sparse::mtimes(const emlrtStack *sp, const ::coder::array<real_T, 1U> &b,
                    ::coder::array<real_T, 1U> &c) const
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack st;
  int32_T nap;
  int32_T nap_tmp;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  if (n != b.size(0)) {
    emlrtErrorWithMessageIdR2018a(sp, &w_emlrtRTEI, "MATLAB:innerdim",
                                  "MATLAB:innerdim", 0);
  }
  st.site = &uh_emlrtRSI;
  c.set_size(&jd_emlrtRTEI, &st, m);
  nap = m;
  for (nap_tmp = 0; nap_tmp < nap; nap_tmp++) {
    c[nap_tmp] = 0.0;
  }
  if ((n != 0) && (m != 0) && (colidx[colidx.size(0) - 1] - 1 != 0)) {
    int32_T b_b;
    b_st.site = &vh_emlrtRSI;
    b_b = n;
    c_st.site = &wh_emlrtRSI;
    if (n > 2147483646) {
      d_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&d_st);
    }
    for (int32_T acol{0}; acol < b_b; acol++) {
      real_T bc;
      int32_T a;
      bc = b[acol];
      a = colidx[acol];
      nap_tmp = colidx[acol + 1];
      nap = nap_tmp - colidx[acol];
      if (nap >= 4) {
        int32_T c_tmp;
        nap = ((nap_tmp - nap) + ((nap / 4) << 2)) - 1;
        c_st.site = &xh_emlrtRSI;
        if ((colidx[acol] <= nap) && (nap > 2147483643)) {
          d_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&d_st);
        }
        for (int32_T ap{a}; ap <= nap; ap += 4) {
          c_tmp = rowidx[ap - 1] - 1;
          c[c_tmp] = c[c_tmp] + d[ap - 1] * bc;
          c[rowidx[ap] - 1] = c[rowidx[ap] - 1] + d[ap] * bc;
          c_tmp = rowidx[ap + 1] - 1;
          c[c_tmp] = c[c_tmp] + d[ap + 1] * bc;
          c_tmp = rowidx[ap + 2] - 1;
          c[c_tmp] = c[c_tmp] + d[ap + 2] * bc;
        }
        nap_tmp = colidx[acol + 1] - 1;
        a = nap + 1;
        c_st.site = &yh_emlrtRSI;
        if ((nap + 1 <= nap_tmp) && (nap_tmp > 2147483646)) {
          d_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&d_st);
        }
        for (int32_T ap{a}; ap <= nap_tmp; ap++) {
          c_tmp = rowidx[ap - 1] - 1;
          c[c_tmp] = c[c_tmp] + d[ap - 1] * bc;
        }
      } else {
        nap = nap_tmp - 1;
        c_st.site = &ai_emlrtRSI;
        if ((colidx[acol] <= nap_tmp - 1) && (nap_tmp - 1 > 2147483646)) {
          d_st.site = &y_emlrtRSI;
          check_forloop_overflow_error(&d_st);
        }
        for (int32_T ap{a}; ap <= nap; ap++) {
          int32_T c_tmp;
          c_tmp = rowidx[ap - 1] - 1;
          c[c_tmp] = c[c_tmp] + d[ap - 1] * bc;
        }
      }
    }
  }
}

void sparse::parenAssign(const emlrtStack *sp,
                         const ::coder::array<real_T, 1U> &rhs,
                         real_T varargin_2)
{
  array<real_T, 2U> b_rhs;
  d_struct_T rhsIter;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  e_st.prev = &d_st;
  e_st.tls = d_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  st.site = &vg_emlrtRSI;
  if (((rhs.size(0) & 65535) + ((rhs.size(0) >> 16) << 16) != m) &&
      (m != rhs.size(0))) {
    emlrtErrorWithMessageIdR2018a(&st, &eb_emlrtRTEI,
                                  "MATLAB:subsassigndimmismatch",
                                  "MATLAB:subsassigndimmismatch", 0);
  }
  if ((rhs.size(0) == 1) && (m != 1)) {
    int32_T extraCol;
    int32_T extraSpace;
    int32_T nzColAlloc;
    int32_T nzRhs;
    b_st.site = &wg_emlrtRSI;
    c_st.site = &yg_emlrtRSI;
    extraSpace = n;
    if ((!(muDoubleScalarFloor(varargin_2) == varargin_2)) ||
        muDoubleScalarIsInf(varargin_2)) {
      emlrtErrorWithMessageIdR2018a(&c_st, &hb_emlrtRTEI,
                                    "Coder:MATLAB:badsubscript",
                                    "Coder:MATLAB:badsubscript", 0);
    }
    if (!(varargin_2 <= extraSpace)) {
      emlrtErrorWithMessageIdR2018a(&c_st, &gb_emlrtRTEI,
                                    "Coder:builtins:IndexOutOfBounds",
                                    "Coder:builtins:IndexOutOfBounds", 6, 6,
                                    varargin_2, 12, 1, 12, extraSpace);
    }
    extraSpace = m;
    rhsIter.idx = 1;
    rhsIter.col = 1;
    rhsIter.row = 1;
    nzColAlloc = colidx[static_cast<int32_T>(varargin_2)] -
                 colidx[static_cast<int32_T>(varargin_2) - 1];
    c_st.site = &ah_emlrtRSI;
    nzRhs = 0;
    d_st.site = &ih_emlrtRSI;
    if (m > 2147483646) {
      e_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&e_st);
    }
    for (extraCol = 0; extraCol < extraSpace; extraCol++) {
      if (!(rhs[extraCol] == 0.0)) {
        nzRhs++;
      }
    }
    if (nzColAlloc < nzRhs) {
      extraCol = nzRhs - nzColAlloc;
      extraSpace = (maxnz - colidx[colidx.size(0) - 1]) + 1;
      if (extraSpace < extraCol) {
        c_st.site = &bh_emlrtRSI;
        sparse::b_realloc(&c_st, this, (maxnz + extraCol) - extraSpace,
                          colidx[static_cast<int32_T>(varargin_2) - 1] - 1,
                          colidx[static_cast<int32_T>(varargin_2)],
                          colidx[colidx.size(0) - 1] - 1, extraCol);
      } else {
        c_st.site = &ch_emlrtRSI;
        extraSpace = colidx[static_cast<int32_T>(varargin_2)];
        nzRhs = (extraSpace + extraCol) - 1;
        nzColAlloc = colidx[colidx.size(0) - 1] - extraSpace;
        if (nzColAlloc > 0) {
          d_st.site = &mh_emlrtRSI;
          std::memmove(
              (void *)&rowidx[nzRhs],
              (void *)&rowidx[colidx[static_cast<int32_T>(varargin_2)] - 1],
              (uint32_T)((size_t)nzColAlloc * sizeof(int32_T)));
          d_st.site = &nh_emlrtRSI;
          std::memmove((void *)&d[nzRhs],
                       (void *)&d[colidx[static_cast<int32_T>(varargin_2)] - 1],
                       (uint32_T)((size_t)nzColAlloc * sizeof(real_T)));
        }
      }
      b_rhs.set_size(&ud_emlrtRTEI, &b_st, 1, 1);
      b_rhs[0] = rhs[0];
      c_st.site = &dh_emlrtRSI;
      sparse::copyNonzeroValues(&c_st, this, &rhsIter,
                                colidx[static_cast<int32_T>(varargin_2) - 1],
                                b_rhs);
      c_st.site = &eh_emlrtRSI;
      sparse::incrColIdx(&c_st, this, static_cast<int32_T>(varargin_2),
                         extraCol);
    } else {
      b_rhs.set_size(&ud_emlrtRTEI, &b_st, 1, 1);
      b_rhs[0] = rhs[0];
      c_st.site = &fh_emlrtRSI;
      extraCol = sparse::copyNonzeroValues(
                     &c_st, this, &rhsIter,
                     colidx[static_cast<int32_T>(varargin_2) - 1], b_rhs) -
                 1;
      extraSpace = nzColAlloc - nzRhs;
      if (extraSpace > 0) {
        c_st.site = &gh_emlrtRSI;
        nzColAlloc = colidx[colidx.size(0) - 1] -
                     colidx[static_cast<int32_T>(varargin_2)];
        if (nzColAlloc > 0) {
          d_st.site = &mh_emlrtRSI;
          std::memmove(
              (void *)&rowidx[extraCol],
              (void *)&rowidx[colidx[static_cast<int32_T>(varargin_2)] - 1],
              (uint32_T)((size_t)nzColAlloc * sizeof(int32_T)));
          d_st.site = &nh_emlrtRSI;
          std::memmove((void *)&d[extraCol],
                       (void *)&d[colidx[static_cast<int32_T>(varargin_2)] - 1],
                       (uint32_T)((size_t)nzColAlloc * sizeof(real_T)));
        }
        c_st.site = &hh_emlrtRSI;
        sparse::decrColIdx(&c_st, this, static_cast<int32_T>(varargin_2),
                           extraSpace);
      }
    }
  } else {
    int32_T extraCol;
    int32_T extraSpace;
    int32_T nzColAlloc;
    int32_T nzColAlloc_tmp;
    int32_T nzRhs;
    b_st.site = &xg_emlrtRSI;
    c_st.site = &yg_emlrtRSI;
    extraSpace = n;
    if ((!(muDoubleScalarFloor(varargin_2) == varargin_2)) ||
        muDoubleScalarIsInf(varargin_2)) {
      emlrtErrorWithMessageIdR2018a(&c_st, &hb_emlrtRTEI,
                                    "Coder:MATLAB:badsubscript",
                                    "Coder:MATLAB:badsubscript", 0);
    }
    if (!(varargin_2 <= extraSpace)) {
      emlrtErrorWithMessageIdR2018a(&c_st, &gb_emlrtRTEI,
                                    "Coder:builtins:IndexOutOfBounds",
                                    "Coder:builtins:IndexOutOfBounds", 6, 6,
                                    varargin_2, 12, 1, 12, extraSpace);
    }
    extraSpace = m;
    rhsIter.idx = 1;
    rhsIter.col = 1;
    rhsIter.row = 1;
    nzColAlloc_tmp = colidx[static_cast<int32_T>(varargin_2)];
    nzColAlloc = nzColAlloc_tmp - colidx[static_cast<int32_T>(varargin_2) - 1];
    c_st.site = &ah_emlrtRSI;
    nzRhs = 0;
    d_st.site = &ih_emlrtRSI;
    if (m > 2147483646) {
      e_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&e_st);
    }
    for (extraCol = 0; extraCol < extraSpace; extraCol++) {
      if (!(rhs[extraCol] == 0.0)) {
        nzRhs++;
      }
    }
    if (nzColAlloc < nzRhs) {
      extraCol = nzRhs - nzColAlloc;
      extraSpace = (maxnz - colidx[colidx.size(0) - 1]) + 1;
      if (extraSpace < extraCol) {
        c_st.site = &bh_emlrtRSI;
        sparse::b_realloc(&c_st, this, (maxnz + extraCol) - extraSpace,
                          colidx[static_cast<int32_T>(varargin_2) - 1] - 1,
                          colidx[static_cast<int32_T>(varargin_2)],
                          colidx[colidx.size(0) - 1] - 1, extraCol);
      } else {
        c_st.site = &ch_emlrtRSI;
        nzRhs = (nzColAlloc_tmp + extraCol) - 1;
        nzColAlloc = colidx[colidx.size(0) - 1] - nzColAlloc_tmp;
        if (nzColAlloc > 0) {
          d_st.site = &mh_emlrtRSI;
          std::memmove(
              (void *)&rowidx[nzRhs],
              (void *)&rowidx[colidx[static_cast<int32_T>(varargin_2)] - 1],
              (uint32_T)((size_t)nzColAlloc * sizeof(int32_T)));
          d_st.site = &nh_emlrtRSI;
          std::memmove((void *)&d[nzRhs],
                       (void *)&d[colidx[static_cast<int32_T>(varargin_2)] - 1],
                       (uint32_T)((size_t)nzColAlloc * sizeof(real_T)));
        }
      }
      c_st.site = &dh_emlrtRSI;
      sparse::copyNonzeroValues(&c_st, this, &rhsIter,
                                colidx[static_cast<int32_T>(varargin_2) - 1],
                                rhs);
      c_st.site = &eh_emlrtRSI;
      sparse::incrColIdx(&c_st, this, static_cast<int32_T>(varargin_2),
                         extraCol);
    } else {
      c_st.site = &fh_emlrtRSI;
      extraCol = sparse::copyNonzeroValues(
                     &c_st, this, &rhsIter,
                     colidx[static_cast<int32_T>(varargin_2) - 1], rhs) -
                 1;
      extraSpace = nzColAlloc - nzRhs;
      if (extraSpace > 0) {
        c_st.site = &gh_emlrtRSI;
        nzColAlloc = colidx[colidx.size(0) - 1] - nzColAlloc_tmp;
        if (nzColAlloc > 0) {
          d_st.site = &mh_emlrtRSI;
          std::memmove(
              (void *)&rowidx[extraCol],
              (void *)&rowidx[colidx[static_cast<int32_T>(varargin_2)] - 1],
              (uint32_T)((size_t)nzColAlloc * sizeof(int32_T)));
          d_st.site = &nh_emlrtRSI;
          std::memmove((void *)&d[extraCol],
                       (void *)&d[colidx[static_cast<int32_T>(varargin_2)] - 1],
                       (uint32_T)((size_t)nzColAlloc * sizeof(real_T)));
        }
        c_st.site = &hh_emlrtRSI;
        sparse::decrColIdx(&c_st, this, static_cast<int32_T>(varargin_2),
                           extraSpace);
      }
    }
  }
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

void sparse::parenReference(const emlrtStack *sp, real_T varargin_2,
                            b_sparse *s) const
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack st;
  int32_T nd_tmp;
  int32_T upperBound;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &pg_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  b_st.site = &qg_emlrtRSI;
  c_st.site = &rg_emlrtRSI;
  upperBound = n;
  if ((!(muDoubleScalarFloor(varargin_2) == varargin_2)) ||
      muDoubleScalarIsInf(varargin_2)) {
    emlrtErrorWithMessageIdR2018a(&c_st, &hb_emlrtRTEI,
                                  "Coder:MATLAB:badsubscript",
                                  "Coder:MATLAB:badsubscript", 0);
  }
  if (!(varargin_2 <= upperBound)) {
    emlrtErrorWithMessageIdR2018a(&c_st, &gb_emlrtRTEI,
                                  "Coder:builtins:IndexOutOfBounds",
                                  "Coder:builtins:IndexOutOfBounds", 6, 6,
                                  varargin_2, 12, 1, 12, upperBound);
  }
  upperBound = colidx[static_cast<int32_T>(varargin_2) - 1];
  nd_tmp = colidx[static_cast<int32_T>(varargin_2)] - upperBound;
  if ((nd_tmp > m) && (m != 0)) {
    emlrtErrorWithMessageIdR2018a(&b_st, &fb_emlrtRTEI,
                                  "Coder:builtins:AssertionFailed",
                                  "Coder:builtins:AssertionFailed", 0);
  }
  c_st.site = &sg_emlrtRSI;
  sparse::spallocLike(&c_st, m, nd_tmp, s);
  if (nd_tmp != 0) {
    c_st.site = &tg_emlrtRSI;
    if (nd_tmp > 2147483646) {
      d_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&d_st);
    }
    for (int32_T k{0}; k < nd_tmp; k++) {
      s->d[k] = 1.0;
      s->rowidx[k] = rowidx[(upperBound + k) - 1];
    }
    s->colidx[1] = s->colidx[0] + nd_tmp;
  }
}

void sparse::permuteVector(const emlrtStack *sp,
                           const ::coder::array<int32_T, 1U> &idx,
                           ::coder::array<int32_T, 1U> &y)
{
  array<int32_T, 1U> t;
  emlrtStack b_st;
  emlrtStack st;
  int32_T loop_ub;
  int32_T ny;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  ny = y.size(0);
  t.set_size(&td_emlrtRTEI, sp, y.size(0));
  loop_ub = y.size(0);
  for (int32_T i{0}; i < loop_ub; i++) {
    t[i] = y[i];
  }
  st.site = &md_emlrtRSI;
  if (y.size(0) > 2147483646) {
    b_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&b_st);
  }
  for (loop_ub = 0; loop_ub < ny; loop_ub++) {
    y[loop_ub] = t[idx[loop_ub] - 1];
  }
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

void sparse::plus(const emlrtStack *sp, const sparse *b, sparse *s) const
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack st;
  int32_T didx;
  boolean_T x[2];
  boolean_T exitg1;
  boolean_T moreAToDo;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &hf_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  if (((m != 1) && (b->m != 1) && (m != b->m)) ||
      ((n != 1) && (b->n != 1) && (n != b->n))) {
    emlrtErrorWithMessageIdR2018a(&st, &ab_emlrtRTEI, "MATLAB:dimagree",
                                  "MATLAB:dimagree", 0);
  }
  b_st.site = &if_emlrtRSI;
  sparse::allocEqsizeBinop(&b_st, this, b, muIntScalarMax_sint32(n, b->n),
                           muIntScalarMax_sint32(m, b->m), s);
  x[0] = (m == b->m);
  x[1] = (n == b->n);
  moreAToDo = true;
  didx = 0;
  exitg1 = false;
  while ((!exitg1) && (didx < 2)) {
    if (!x[didx]) {
      moreAToDo = false;
      exitg1 = true;
    } else {
      didx++;
    }
  }
  if (moreAToDo) {
    b_st.site = &jf_emlrtRSI;
    sparse::sparseSparseEqHeightBinOp(&b_st, this, b, s);
  } else if (n == 1) {
    if (b->m == 1) {
      b_st.site = &kf_emlrtRSI;
      sparse::c_sparseSparseRowExpandBinOp(&b_st, b, this, s);
    } else {
      int32_T b_n;
      b_st.site = &lf_emlrtRSI;
      didx = 0;
      s->colidx[0] = 1;
      b_n = s->n;
      c_st.site = &rf_emlrtRSI;
      if (s->n > 2147483646) {
        d_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&d_st);
      }
      for (int32_T c{0}; c < b_n; c++) {
        int32_T aidx;
        int32_T bidx;
        int32_T bidx_tmp;
        boolean_T moreBToDo;
        aidx = colidx[0];
        bidx_tmp = b->colidx[c];
        bidx = bidx_tmp - 1;
        moreAToDo = (colidx[0] < colidx[1]);
        moreBToDo = (bidx_tmp < b->colidx[c + 1]);
        while (moreAToDo || moreBToDo) {
          while ((aidx < colidx[1]) &&
                 ((!moreBToDo) || (rowidx[aidx - 1] < b->rowidx[bidx]))) {
            s->d[didx] = 1.0;
            s->rowidx[didx] = rowidx[aidx - 1];
            didx++;
            aidx++;
          }
          moreAToDo = (aidx < colidx[1]);
          while ((bidx + 1 < b->colidx[c + 1]) &&
                 ((!moreAToDo) || (b->rowidx[bidx] < rowidx[aidx - 1]))) {
            if (b->d[bidx] != 0.0) {
              s->d[didx] = b->d[bidx];
              s->rowidx[didx] = b->rowidx[bidx];
              didx++;
            }
            bidx++;
          }
          while ((aidx < colidx[1]) && (bidx + 1 < b->colidx[c + 1]) &&
                 (rowidx[aidx - 1] == b->rowidx[bidx])) {
            if (b->d[bidx] + 1.0 != 0.0) {
              s->d[didx] = b->d[bidx] + 1.0;
              s->rowidx[didx] = b->rowidx[bidx];
              didx++;
            }
            bidx++;
            aidx++;
          }
          moreAToDo = (aidx < colidx[1]);
          moreBToDo = (bidx + 1 < b->colidx[c + 1]);
        }
        s->colidx[c + 1] = didx + 1;
      }
    }
  } else if (b->n == 1) {
    if (m == 1) {
      b_st.site = &mf_emlrtRSI;
      sparse::sparseSparseRowExpandBinOp(&b_st, this, b, s, true);
    } else {
      int32_T b_n;
      b_st.site = &nf_emlrtRSI;
      didx = 0;
      s->colidx[0] = 1;
      b_n = s->n;
      c_st.site = &rf_emlrtRSI;
      if (s->n > 2147483646) {
        d_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&d_st);
      }
      for (int32_T c{0}; c < b_n; c++) {
        int32_T aidx;
        int32_T bidx;
        int32_T bidx_tmp;
        boolean_T moreBToDo;
        aidx = b->colidx[0] - 1;
        bidx_tmp = colidx[c];
        bidx = bidx_tmp - 1;
        moreAToDo = (b->colidx[0] < b->colidx[1]);
        moreBToDo = (bidx_tmp < colidx[c + 1]);
        while (moreAToDo || moreBToDo) {
          while ((aidx + 1 < b->colidx[1]) &&
                 ((!moreBToDo) || (b->rowidx[aidx] < rowidx[bidx]))) {
            if (b->d[aidx] != 0.0) {
              s->d[didx] = b->d[aidx];
              s->rowidx[didx] = b->rowidx[aidx];
              didx++;
            }
            aidx++;
          }
          moreAToDo = (aidx + 1 < b->colidx[1]);
          while ((bidx + 1 < colidx[c + 1]) &&
                 ((!moreAToDo) || (rowidx[bidx] < b->rowidx[aidx]))) {
            s->d[didx] = 1.0;
            s->rowidx[didx] = rowidx[bidx];
            didx++;
            bidx++;
          }
          while ((aidx + 1 < b->colidx[1]) && (bidx + 1 < colidx[c + 1]) &&
                 (b->rowidx[aidx] == rowidx[bidx])) {
            if (b->d[aidx] + 1.0 != 0.0) {
              s->d[didx] = b->d[aidx] + 1.0;
              s->rowidx[didx] = rowidx[bidx];
              didx++;
            }
            bidx++;
            aidx++;
          }
          moreAToDo = (aidx + 1 < b->colidx[1]);
          moreBToDo = (bidx + 1 < colidx[c + 1]);
        }
        s->colidx[c + 1] = didx + 1;
      }
    }
  } else if (m == 1) {
    b_st.site = &of_emlrtRSI;
    sparse::sparseSparseRowExpandBinOp(&b_st, this, b, s, false);
  } else if (b->m == 1) {
    b_st.site = &pf_emlrtRSI;
    sparse::d_sparseSparseRowExpandBinOp(&b_st, b, this, s);
  }
}

void sparse::spallocLike(const emlrtStack *sp, int32_T b_m, real_T b_n,
                         sparse *s)
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack st;
  int32_T s_tmp_tmp;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &af_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  b_st.site = &rc_emlrtRSI;
  if (b_m < 0) {
    emlrtErrorWithMessageIdR2018a(&b_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (b_m >= MAX_int32_T) {
    emlrtErrorWithMessageIdR2018a(
        &b_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  b_st.site = &sc_emlrtRSI;
  c_st.site = &nd_emlrtRSI;
  if ((b_n != b_n) || muDoubleScalarIsInf(b_n)) {
    emlrtErrorWithMessageIdR2018a(
        &c_st, &j_emlrtRTEI, "Coder:MATLAB:NonIntegerInput",
        "Coder:MATLAB:NonIntegerInput", 4, 12, MIN_int32_T, 12, MAX_int32_T);
  }
  if (b_n < 0.0) {
    emlrtErrorWithMessageIdR2018a(&b_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (!(b_n < 2.147483647E+9)) {
    emlrtErrorWithMessageIdR2018a(
        &b_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  s->m = b_m;
  s_tmp_tmp = static_cast<int32_T>(b_n);
  s->n = static_cast<int32_T>(b_n);
  s->d.set_size(&hd_emlrtRTEI, &st, 1);
  s->d[0] = 0.0;
  s->maxnz = 1;
  if (static_cast<int32_T>(b_n) + 1 < 0) {
    emlrtNonNegativeCheckR2012b(
        static_cast<real_T>(static_cast<int32_T>(b_n) + 1), &d_emlrtDCI, &st);
  }
  s->colidx.set_size(&rc_emlrtRTEI, &st, static_cast<int32_T>(b_n) + 1);
  s->colidx[0] = 1;
  s->rowidx.set_size(&hd_emlrtRTEI, &st, 1);
  s->rowidx[0] = 0;
  b_st.site = &uc_emlrtRSI;
  if (static_cast<int32_T>(b_n) > 2147483646) {
    c_st.site = &y_emlrtRSI;
    check_forloop_overflow_error(&c_st);
  }
  for (int32_T c{0}; c < s_tmp_tmp; c++) {
    s->colidx[c + 1] = 1;
  }
  b_st.site = &wc_emlrtRSI;
  s->fillIn();
}

void sparse::spallocLike(const emlrtStack *sp, int32_T b_m, int32_T nzmax,
                         b_sparse *s)
{
  emlrtStack b_st;
  emlrtStack st;
  int32_T numalloc;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &af_emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  b_st.site = &rc_emlrtRSI;
  if (b_m < 0) {
    emlrtErrorWithMessageIdR2018a(&b_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (b_m >= MAX_int32_T) {
    emlrtErrorWithMessageIdR2018a(
        &b_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  s->m = b_m;
  b_st.site = &de_emlrtRSI;
  if (nzmax < 0) {
    emlrtErrorWithMessageIdR2018a(&b_st, &r_emlrtRTEI,
                                  "Coder:toolbox:SparseNegativeSize",
                                  "Coder:toolbox:SparseNegativeSize", 0);
  }
  if (nzmax >= MAX_int32_T) {
    emlrtErrorWithMessageIdR2018a(
        &b_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
        "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
  }
  numalloc = muIntScalarMax_sint32(nzmax, 1);
  s->d.set_size(&hd_emlrtRTEI, &st, numalloc);
  for (int32_T i{0}; i < numalloc; i++) {
    s->d[i] = 0.0;
  }
  s->colidx.set_size(&rc_emlrtRTEI, &st, 2);
  s->rowidx.set_size(&hd_emlrtRTEI, &st, numalloc);
  for (int32_T i{0}; i < numalloc; i++) {
    s->rowidx[i] = 0;
  }
  s->colidx[0] = 1;
  s->colidx[1] = 1;
}

void sparse::times(const emlrtStack *sp, real_T a, sparse *s) const
{
  array<real_T, 2U> S;
  array<real_T, 1U> tmpd;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  emlrtStack f_st;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  e_st.prev = &d_st;
  e_st.tls = d_st.tls;
  f_st.prev = &e_st;
  f_st.tls = e_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b((emlrtCTX)sp);
  st.site = &re_emlrtRSI;
  if (a * 0.0 == 0.0) {
    int32_T b_n;
    int32_T col;
    int32_T loop_ub;
    int32_T numalloc;
    b_st.site = &se_emlrtRSI;
    c_st.site = &ve_emlrtRSI;
    b_n = colidx[colidx.size(0) - 1];
    if (colidx[colidx.size(0) - 1] - 1 < 1) {
      loop_ub = 0;
    } else {
      loop_ub = colidx[colidx.size(0) - 1] - 1;
    }
    tmpd.set_size(&cd_emlrtRTEI, &c_st, loop_ub);
    for (col = 0; col < loop_ub; col++) {
      tmpd[col] = a * d[col];
    }
    if (tmpd.size(0) != colidx[colidx.size(0) - 1] - 1) {
      emlrtErrorWithMessageIdR2018a(&c_st, &y_emlrtRTEI, "MATLAB:samelen",
                                    "MATLAB:samelen", 0);
    }
    d_st.site = &we_emlrtRSI;
    e_st.site = &af_emlrtRSI;
    f_st.site = &rc_emlrtRSI;
    if (m < 0) {
      emlrtErrorWithMessageIdR2018a(&f_st, &r_emlrtRTEI,
                                    "Coder:toolbox:SparseNegativeSize",
                                    "Coder:toolbox:SparseNegativeSize", 0);
    }
    if (m >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &f_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    f_st.site = &sc_emlrtRSI;
    if (n < 0) {
      emlrtErrorWithMessageIdR2018a(&f_st, &r_emlrtRTEI,
                                    "Coder:toolbox:SparseNegativeSize",
                                    "Coder:toolbox:SparseNegativeSize", 0);
    }
    if (n >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &f_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    s->m = m;
    s->n = n;
    f_st.site = &de_emlrtRSI;
    if (colidx[colidx.size(0) - 1] - 1 < 0) {
      emlrtErrorWithMessageIdR2018a(&f_st, &r_emlrtRTEI,
                                    "Coder:toolbox:SparseNegativeSize",
                                    "Coder:toolbox:SparseNegativeSize", 0);
    }
    if (colidx[colidx.size(0) - 1] - 1 >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &f_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    if (colidx[colidx.size(0) - 1] - 1 < 0) {
      emlrtErrorWithMessageIdR2018a(&e_st, &v_emlrtRTEI,
                                    "Coder:toolbox:SparseNzmaxTooSmall",
                                    "Coder:toolbox:SparseNzmaxTooSmall", 0);
    }
    numalloc = colidx[colidx.size(0) - 1] - 1;
    numalloc = muIntScalarMax_sint32(numalloc, 1);
    s->d.set_size(&bd_emlrtRTEI, &e_st, numalloc);
    for (col = 0; col < numalloc; col++) {
      s->d[col] = 0.0;
    }
    s->maxnz = numalloc;
    s->colidx.set_size(&rc_emlrtRTEI, &e_st, n + 1);
    s->rowidx.set_size(&bd_emlrtRTEI, &e_st, numalloc);
    for (col = 0; col < numalloc; col++) {
      s->rowidx[col] = 0;
    }
    numalloc = n;
    for (loop_ub = 0; loop_ub < numalloc; loop_ub++) {
      s->colidx[loop_ub + 1] = 1;
    }
    col = s->colidx.size(0);
    for (loop_ub = 0; loop_ub <= col - 2; loop_ub++) {
      s->colidx[loop_ub] = 1;
    }
    if (colidx[colidx.size(0) - 1] - 1 < 1) {
      loop_ub = 1;
    } else {
      loop_ub = colidx[colidx.size(0) - 1];
    }
    for (col = 0; col <= loop_ub - 2; col++) {
      s->rowidx[col] = rowidx[col];
    }
    s->colidx.set_size(&bd_emlrtRTEI, &c_st, colidx.size(0));
    loop_ub = colidx.size(0);
    for (col = 0; col < loop_ub; col++) {
      s->colidx[col] = colidx[col];
    }
    d_st.site = &xe_emlrtRSI;
    if (colidx[colidx.size(0) - 1] - 1 > 2147483646) {
      e_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&e_st);
    }
    for (loop_ub = 0; loop_ub <= b_n - 2; loop_ub++) {
      s->d[loop_ub] = tmpd[loop_ub];
    }
    d_st.site = &ye_emlrtRSI;
    s->b_fillIn();
  } else {
    int32_T b_n;
    int32_T col;
    int32_T loop_ub;
    int32_T mInt;
    int32_T nInt;
    int32_T numalloc;
    S.set_size(&ad_emlrtRTEI, &st, m, n);
    loop_ub = m * n;
    for (col = 0; col < loop_ub; col++) {
      S[col] = rtNaN;
    }
    b_st.site = &te_emlrtRSI;
    b_n = n;
    c_st.site = &bf_emlrtRSI;
    if (n > 2147483646) {
      d_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&d_st);
    }
    for (col = 0; col < b_n; col++) {
      numalloc = colidx[col];
      loop_ub = colidx[col + 1] - 1;
      c_st.site = &cf_emlrtRSI;
      if ((colidx[col] <= loop_ub) && (loop_ub > 2147483646)) {
        d_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&d_st);
      }
      for (mInt = numalloc; mInt <= loop_ub; mInt++) {
        S[(rowidx[mInt - 1] + S.size(0) * col) - 1] = a * d[mInt - 1];
      }
    }
    b_st.site = &ue_emlrtRSI;
    c_st.site = &mc_emlrtRSI;
    mInt = S.size(0);
    nInt = S.size(1);
    d_st.site = &df_emlrtRSI;
    e_st.site = &nd_emlrtRSI;
    if (S.size(0) >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &d_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    d_st.site = &ef_emlrtRSI;
    e_st.site = &nd_emlrtRSI;
    if (S.size(1) >= MAX_int32_T) {
      emlrtErrorWithMessageIdR2018a(
          &d_st, &s_emlrtRTEI, "Coder:toolbox:SparseMaxSize",
          "Coder:toolbox:SparseMaxSize", 2, 12, MAX_int32_T);
    }
    b_n = 0;
    col = S.size(0) * S.size(1);
    for (loop_ub = 0; loop_ub < col; loop_ub++) {
      if (S[loop_ub] != 0.0) {
        b_n++;
      }
    }
    s->m = S.size(0);
    s->n = S.size(1);
    numalloc = muIntScalarMax_sint32(b_n, 1);
    s->maxnz = numalloc;
    s->d.set_size(&bd_emlrtRTEI, &c_st, numalloc);
    for (col = 0; col < numalloc; col++) {
      s->d[col] = 0.0;
    }
    s->colidx.set_size(&bd_emlrtRTEI, &c_st, S.size(1) + 1);
    loop_ub = S.size(1);
    for (col = 0; col <= loop_ub; col++) {
      s->colidx[col] = 0;
    }
    s->colidx[0] = 1;
    s->rowidx.set_size(&bd_emlrtRTEI, &c_st, numalloc);
    for (col = 0; col < numalloc; col++) {
      s->rowidx[col] = 0;
    }
    s->rowidx[0] = 1;
    numalloc = 0;
    d_st.site = &ff_emlrtRSI;
    for (col = 0; col < nInt; col++) {
      d_st.site = &gf_emlrtRSI;
      if (mInt > 2147483646) {
        e_st.site = &y_emlrtRSI;
        check_forloop_overflow_error(&e_st);
      }
      for (loop_ub = 0; loop_ub < mInt; loop_ub++) {
        real_T xrc;
        xrc = S[loop_ub + S.size(0) * col];
        if (xrc != 0.0) {
          s->rowidx[numalloc] = loop_ub + 1;
          s->d[numalloc] = xrc;
          numalloc++;
        }
      }
      s->colidx[col + 1] = numalloc + 1;
    }
  }
  emlrtHeapReferenceStackLeaveFcnR2012b((emlrtCTX)sp);
}

} // namespace coder

// End of code generation (sparse1.cpp)
